I read this question but it did not help much because of success:function. it do not understand completion of Ajax response. Do anyone know how to use Ajax stop for specific events ?
Detail : I have an Ajax code which sends a request and I want it to do something when it gets a response. I do that by the following function but it gets all documents of Ajax and I cant add any Ajax to the page.
$(document).ajaxStop(function() {
....;
alert("start");
});
ajaxStop
is meant to be used for a global AJAX completion behavior. You probably want to use a regular complete
handler:
$.ajax({
url: "some/path.php",
complete: function() { alert("start"); }
});
or alternatively you can use the always
promise method:
$.ajax({
url: "http://fiddle.jshell.net/favicon.png",
}).always(function() {
alert("start");
});
UPDATE:
Looking at your comments below, you might actually want to use success (especially when you are interested in the response
:
$.ajax({
url: "some/path.php",
success: function(response) { alert(response); }
});
or alternatively you can use the done
promise method:
$.ajax({
url: "http://fiddle.jshell.net/favicon.png",
}).done(function(response) {
alert(response);
});
However, it is important to note that both of those methods only execute when you receive a successful response from the server (status code 200).