JQuery Ajax control
- by Anycolor
Everybody hi.
There is a problem with my own AJAX library, that I can't solve.
I have some block (#ajax-loading), that has events:
$('#ajax-loading')
.bind('ajaxStart', function() {
$('#ajax-loading').show();
})
.bind('ajaxStop', function() {
$('#ajax-loading').fadeOut(150);
});
For running AJAX I have special method:
run: function(data, callback) {
if(this.request) {
this.request.abort();
}
this.request = $.getJSON(window.location.pathname, data , callback);
},
So .request holds current AJAX request.
What do I want? My #ajax-loading block contains the button, than should Cancel current AJAX request. As I supposed, the function, making Cancel shoud contain:
abort: function() {
if(ajax.request) {
this.request.abort();
$('#ajax-loading').fadeOut(150);
}
}
But, as I said, there is a problem: my AJAX request cancels, loading-block hides, but when another request starts, this block doesn't shows again.
It seems that when I abort AJAX request, the ajaxStop event doesn't happen. And when I run new request ajaxStart doesn't happen.
I think it can be connected with readyState or status field of XMLHttpRequest, or smth similar.
Could anyone help me with this or explain what's wrong.
PS: excuse my english, it's not my native language...