tags:

views:

79

answers:

2

I set the global ajaxSend callback as below in my $(document).ready function.

 // global AJAX methods
 $(document).ajaxSend(function(e, xhr, settings) {
  alert('here');
    });

However, I am never getting here even though I have several $.ajax() calls that run successfully after the document has loaded and on demand. Yet, here appears when I calling $.post.

Do global methods not call for $.ajax requests? I have not modified the global param, so they should.

I am fine using the beforeSend, but I need access to the url and other request data.

Any ideas would be appreciated as I have yet to find any gotchas from the docs.

A: 

since it's a callback it doesn't need to be in $(document).ready. It can be a standard function.


set your callback function in your $.ajax calls and everything will be fine.

[edit]

function ajaxSend(data)
{
alert('hello');
}

$.ajax({url: [url],
            type: 'POST',
            cache: false,
            data: oData,
            success: ajaxSend});    

keeping it easy.. :)

Sirber
Please elaborate or provide a code sample. Your suggestion is unclear.
Jason McCreary
Thanks for the elaboration. Please note that `ajaxSend` is a global callback method. Your recent post could be misleading. However, moving `$(document).ajaxSend(...)` outside `$(document).ready` per your original suggestion resolved the problem. Rookie mistake.
Jason McCreary
added some code. I hope I understood the OP's question right.
Sirber
@Jason: http://api.jquery.com/ajaxSend/ you are right, sorry I thought it was a handmade function.
Sirber
A: 

Are you using IE by the way? If so it caches ajax calls which are not posts.

see this link: http://stackoverflow.com/questions/425854/jquery-ajax-request-failing-in-ie

Richard
Not using IE, thanks for the link though.
Jason McCreary