1

can't seem to get the ajaxSend and Stop to work... These are global variables no? .. but I should be able to use like this... but I never get an alert??

I wanted to use these events to display an ajax animation.. although in my code I wish to position the ajax animation depending on what I am doing a what element it is.

$.ajax({
    type: "POST",
    url: "MyService.aspx/TestMe",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    ajaxSend: function (r, s) {
        alert('i am starting');
    }
    ,
    ajaxStop: function (r, s) {
        alert('i am stopping');
    }
    ,
    success: function (msg) {
    }
});

2 Answers 2

3

Those are globals, and the way I typically see them assigned is:

$('element').ajaxStart(function() {
 ... do something ...
}

Assigning them to a specific ajax request, I'm not sure if that will do what you want it to do.

Sign up to request clarification or add additional context in comments.

1 Comment

For posterity, it does work.
2

So you don't use this functionality properly. ajaxStop, ajaxComplete and etc. is not a parameters of $.ajax function. Let say you have an ajax icon which you want to remove on request completion.

 $("#ajax_icon").ajaxStop(function(){
   $(this).hide();
 });

You have a good reference here

PS. With other function is the same.

1 Comment

As of jQuery 1.8 you should only attach those handlers to the document: $(document).ajaxStop(function () { })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.