weixin_33739541 2017-08-22 10:49 采纳率: 0%
浏览 13

jQuery更新1-3代码问题

I have a older script that I use to use. I am not a jquery type person and I am having difficulties getting a script to work.

I am using jquery 3.2.1 but I can only get this to work using jquery 1.11.1 I am not sure what I am looking for or what is causing the issue.

the script is located here http://www.2my4edge.com/2013/07/username-live-availability-check-using.html

This issue code

$(document).ready(function(){

$("#username").change(function(){

var username = $("#username").val();
var msgbox = $("#status");

if(username.length > 4){

$("#status").html('<img src="loader.gif" align="absmiddle"> Checking availability...');

$.ajax({  
    type: "POST",  
    url: "ajax.php",  
    data: "username="+ username,  
    success: function(msg){  
   $("#status").ajaxComplete(function(event, request){
    if(msg == 'OK')    {

        $("#username").removeClass("red");
        $("#username").addClass("green");
        msgbox.html('<img src="available.png" align="absmiddle">');

    } else  {

         $("#username").removeClass("green");
         $("#username").addClass("red");
        msgbox.html(msg);
    }  

   });
   }

 });

} else {
$("#username").addClass("red");
$("#status").html('<font color="#cc0000">Please enter atleast 5 letters</font>');
}
return false;
});

});
  • 写回答

2条回答 默认 最新

  • weixin_33709219 2017-08-22 13:29
    关注

    Yoy are using ajaxComplete inside success callback function, that doesn't make sense, since success callback will fire when ajax finishes. Also, according to .ajaxComplete() :

    As of jQuery 1.9, all the handlers for the jQuery global Ajax events, including those added with the .ajaxComplete() method, must be attached to document.

    Try to remove the line:

    $("#status").ajaxComplete(function(event, request){
    

    and its closing bracket and parenthesis:

    });
    

    Also, $(document).ready(function(){ is deprecated in jQuery 3. Replace it with $(function() {

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?