ajaxStart和ajaxStop无法正常工作

3

一开始,我在我的页面中尝试使用ajaxStartajaxStop,但它们没有起作用,代码如下:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script language="javascript" src="jquery-1.11.1.js"></script>
</head>
<body>
<form name="form" method="post" action="">
    <input id = "name" type="text" name = "name" value="">
    <div id = "check"></div>
</form>

<script language="javascript">
       $("#name").blur(function() {
           $("#name").ajaxStart(function() {
               $("#check").html("loading...");
               alert("loading...");
           });
           $("#name").ajaxStop(function() {
               $("#check").html("OK...");
               alert("OK...");
           });
           $.ajaxSetup({
               url : "check.php",
               type : "POST",
               success : function(data) {
                   $("#check").html(data);
               },
           });
           $.ajax({
               url : "checkname.php",
               type : "POST",
               data : {name : $("#name").val()},
               datatype : "text",
               beforeSend : function() {
                   console.log("beforeSend");
               },
               success : function(data) {
                   $("#check").html(data);
                   console.log("success");
               },
               error : function() {
                   $("#check").html("error");
                   console.log("error");
               },
               complete : function() {
                   console.log("complete");
               },
           });
       });
</script>
</body>
</html>

然后,我找到了一个答案stackoverflow.com/questions/4034252/jquery-ajaxstart-not-working 告诉我要使用document,当我使用以下代码时,它就起作用了

$(document).ajaxStart(function() {
    $("#check").html("loading...");
    alert("loading...");   
});

另外,我尝试了另一种方法,使用jQuery 1.7.2,在$("#name").ajaxStart()上有效。

我的问题是:

1、为什么在jQuery 1.11.1中$("#name").ajaxStart()无效了?从1.7.2版本到现在发生了什么变化?

2、有没有一些网站可以给我提供每个版本jQuery的区别,详细信息将更好。

非常感谢您的帮助。

1个回答

3

1)正如jQuery官方文档这里所述, 自jQuery 1.8以来,.ajaxStart()方法只应附加到document。

2)对于您的第二个查询,jQuery官方文档应该足够 有关弃用的内容,请在此处查看


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接