0

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.

Scott Evernden
  • 39,136
  • 15
  • 78
  • 84
Jason McCreary
  • 71,546
  • 23
  • 135
  • 174

2 Answers2

0

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

see this link: jQuery AJAX request failing in IE

Community
  • 1
  • 1
Richard
  • 21,728
  • 13
  • 62
  • 101
-2

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
  • 3,358
  • 5
  • 25
  • 32
  • Please elaborate or provide a code sample. Your suggestion is unclear. – Jason McCreary Jul 23 '10 at 15:54
  • 4
    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 Jul 23 '10 at 17:50
  • added some code. I hope I understood the OP's question right. – Sirber Jul 23 '10 at 17:50
  • @Jason: http://api.jquery.com/ajaxSend/ you are right, sorry I thought it was a handmade function. – Sirber Jul 23 '10 at 17:52
  • @Jason McCreary You should consider putting that comment as an answer because it is correct. This answer is not correct at all. Thanks! – locrizak Jun 15 '12 at 15:45
  • @locrizak, I can't remember that far back :) However, I feel this answer solved my problem and the comment chain should make it clear. – Jason McCreary Jun 15 '12 at 16:04