I'll bet your document has six DOM elements (HTML tags) in it, right? The
$('*') selector is selecting *all* of those elements, and the ajaxSend
callback is getting called for each one.
Try something like $('body').ajaxSend(...) if you want just a single
callback.
I never noticed it before - I haven't used these ajax event notifications
functions - but this seems like a strange design. They are really global
notifications; it's hard to imagine why they should be attached to
individual DOM elements. Take the example for ajaxStart from the docs:
$("#loading").ajaxStart(function(){
$(this).show();
});
At least to my way of thinking, this would have made more sense as a global
jQuery function:
$.ajaxStart(function(){
$("#loading").show();
});
Ah well, it's water under the bridge now...
-Mike
> From: Lay András
>
> Hello!
>
> I need a callback to be executed, when any ajax request
> begins. I used this code:
>
> var cnt=0;
> $('*').ajaxSend(function() {
> cnt++;
> });
> function Teszt() {
> $.post('jquerytest.php');
> alert(cnt);
> }
>
> When i call function Teszt(), the alert shows '6'. Why?
>