iatboy
iatboy

Reputation: 1293

ajaxStart and ajaxStop not working

In the beginning, I tried ajaxStart and ajaxStop in my page, and they did not work, the code :

<!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>

Then, I found one answer stackoverflow.com/questions/4034252/jquery-ajaxstart-not-working told me to use document instead, and when I used the following code it works

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

Also, I tried another way, use jQuery 1.7.2 and it works on $("#name").ajaxStart()

My question are :

1、Why in jQuery 1.11.1 the $("#name").ajaxStart() does not work, what has changed from 1.7.2?

2、Are there some websites to give me the difference of each version of jQuery, details will be better.

Any help will be appreciated, thanks.

Upvotes: 3

Views: 4322

Answers (1)

Domain
Domain

Reputation: 11808

1) As stated here in jQuery official documentation, As of jQuery 1.8, the .ajaxStart() method should only be attached to document.

2) For your 2nd query, jQuery official documentation should be sufficient For deprecated things go here

Upvotes: 3

Related Questions