how can i know the readystates of an ajax request through jquery ?
In general, without using jquery, we will send an ajax request like this:
http.open("POST", url, true);
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
// do something
}
}
So i can easily track the readystate value from 1 to 4 using the above code, and perform necessary action like showing a loading icon when readystate is 1.
But through a jquery ajax call, how can i track the readystate values ?
I am making an ajax call through jquery like this:
$.post('ajax/test.html', function(data) {
$('.result').html(data);
});
Have a look at the documentation of
$.ajax. You have the possibility to pass different callbacks (maybe not for evert “ready state” but it is enough for an indicator):So the best idea would be to show the indicator in the callback passed to
beforeSendand hide it incomplete.Example:
So you would have to rewrite your code as:
although I don’t understand why you use POST as your are not sending any data (at least in your example code).