jQuery和ajaxSend不触发


                    

我在 $(document).ready </ code>函数中按如下所示设置全局 ajaxSend </ code>回调。</ p>

  //全局AJAX方法
  $(document).ajaxSend(function(e,xhr,settings){
   警报(这里)
     });
</ code> </ pre>

但是,即使我有几个 $。ajax()</ code>调用都可以在文档加载后按需成功运行,但我从没有得到 here </ em>。 但是,当我呼叫 $。post </ code>时,会出现此处</ em>。</ p>

全局方法是否不调用 $。ajax </ code>请求? 我还没有修改 global </ code>参数,所以应该。</ p>

使用 beforeSend </ code>很好,但是我需要访问url和其他请求数据。</ p>

任何想法都会受到赞赏,因为我还没有从文档中找到任何陷阱。</ p>
     </ div>

展开原文

原文

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.

2个回答


因为它是一个回调,所以它不需要在 $(document).ready </ code>中。 它可以是标准功能。</ p>


在您的 $。ajax </ code>调用中设置回调函数,一切都会好起来的。</ p>

[编辑] </ p>

 函数ajaxSend(数据)
{
警报('你好');
}

$ .ajax({url:[url],
             输入:“ POST”,
             快取:false,
             数据:oData,
             成功:ajaxSend});
</ code> </ pre>

保持简单..:)</ p>
     </ div>

展开原文

原文

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.. :)


您是否正在使用IE? 如果是这样,它将缓存不是帖子的ajax调用。</ p>

查看此链接:
jQuery AJAX请求在IE中失败 </ p>
     </ div>

展开原文

原文

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问