jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jQuery Ajax成功/错误回调没有在IE中触发大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直试图让ajax调用在IE9中正常工作.我可以在网络数据中看到请求通过正常.并且jQuery $.ajax()调用返回的jqXHR对象包含响应数据.然而,我的成功/错误/完整回调没有解雇.这是代码……

在我的脚本的顶部:

// override xhr for browser that use XDR
if ('XDomainrequest' in window && window.XDomainrequest !== null) {

  // override default jQuery transport for IE
  jQuery.ajaxSetTings.xhr = function() {
      try { return new XDomainrequest(); }
      catch(E) {
        console.log('test'); 
      }
  };

  // Maybe a 304 response is causing the callBACks not to fire?
  // This makes sure I'm getTing 200
  jQuery.ajaxSetTings.cache = false;

  // also,override the support check
  jQuery.support.cors = true;
}

然后我的ajax电话……非常简单.

$.ajax({
    url: url,success: success,complete: complete,beforeSend: beforeSend,error: error
});

function success(response,textStatus,jqXHR){
    console.log('success');
    if( typeof fn == 'function'){
        fn(response.data);
    } else {
        console.log('Invalid callBACk supplied for dataGateway');
    }
}

function error(jqXHR,errorThrown){
    console.log("Could not retrieve data from API.");
    return;
}

function complete(jqXHR,textStatus){
    console.log('complete');
}

// This is the only callBACk that gets fired
function beforeSend(jqXHR,setTings){
    console.log('before send');
}

有人知道如何解决这个问题吗?

解决方法

不知道这是否有帮助,但这是我工作的ajax调用一个例子.

$.ajax({
        url: "http://myurl.com",type: "POST",dataType: "xml",data: GetCurrentUserSoapEnv,//my variable containing the xml I sending
        complete: processResult,//the function to call on completion
        contentType: "text/xml; charset=\"utf-8\""
});

大佬总结

以上是大佬教程为你收集整理的jQuery Ajax成功/错误回调没有在IE中触发全部内容,希望文章能够帮你解决jQuery Ajax成功/错误回调没有在IE中触发所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。