AJAX请求仅使IE失败


                    

以下ajax调用在Chrome / FF中工作正常,但仅在IE中失败。
我尝试过关闭缓存,物理/相对路径,打开和关闭异步,但是没有任何运气。 我整个上午一直在寻找和测试不同的解决方案,但是我仍然没有运气。</ p>

返回的错误代码不是很有帮助:未定义错误</ code> </ p>

有什么想法吗?</ p>

 功能CreateCard(//一堆参数//){

                 var soapMessage ='//长肥皂串很大///';
                 var webServiceURL =“ //消费网址(相对)”;

                 $ .ajax({
                     网址:webServiceURL,
                     输入:“ POST”,
                     crossDomain:是的,
                     dataType:“ xml”,
                     数据:soapMessage,
                     processData:否,
                     contentType:“ text / xml; charset = \” utf-8 \“”,
                     成功:函数(数据,状态,要求,xml,xmlHttpRequest,responseXML){
                         var newCardID = $(req.responseXML).find('AddeCardRequestResult')。text(); //获取新卡号
                         $('div#debug')。html(“成功:” + newCardID)
                         $('#CID')。val(newCardID);

                         __doPostBack('btnSubmit',newCardID);

                     },
                     错误:function(xhr,msg){
                         $('div#debug')。html(msg +'
'+ xhr.responseText)
                     }
                 });

             }
</ code> </ pre>
     </ div>

展开原文

原文

The following ajax call works just fine in Chrome/FF, but is failing in IE only. I've tried turning cache off, physical/relative paths, async on and off, but not having any luck. I've been cruising around in SO all morning finding and testing different solutions, but I'm still not having any luck.

The error code returned isn't terribly helpful: error undefined

Any Ideas?

function CreateCard(//a bunch of paramaters//){



                var soapMessage ='//big long soap string goes here//';          
                var webServiceURL="//consumption URL (relative)";


                $.ajax({
                    url: webServiceURL, 
                    type: "POST",
                    crossDomain: true,
                    dataType: 'xml',
                    data: soapMessage, 
                    processData: false,
                    contentType: "text/xml; charset=\"utf-8\"",
                    success: function(data, status, req, xml, xmlHttpRequest, responseXML) { 
                        var newCardID=$(req.responseXML).find('AddeCardRequestResult').text();  //Fetches new card id
                        $('div#debug').html("success: " + newCardID)  
                        $('#CID').val(newCardID);

                        __doPostBack('btnSubmit', newCardID);

                    }, 
                    error: function(xhr, msg) { 
                        $('div#debug').html(msg + '
' + xhr.responseText)
                    } 
                });




            }

2个回答


这里的答案仅是突出显示OP问题中评论的最终结果:</ p>

webServiceURL </ code>与脚本位于同一域中,因此 crossDomain:true,</ code>是不必要的。</ p>

数据:soapMessage </ code>,也可能引起问题,因为AJAX指定了POST,而 soapMessage </ code>是XML字符串,该字符串转换为附加到URL的查询字符串。 </ p>
     </ div>

展开原文

原文

This answer is here to simply highlight the end result of the comments in OP's question:

webServiceURL is on the same domain as the script so crossDomain: true, is unnecessary.

data: soapMessage, is probably also causing an issue because AJAX is specifying a POST but soapMessage is an XML string which gets converted to a querystring appended to the URL.


使用ie,您将需要在请求中添加某种随机参数。</ p>

我通常使用(new Date())。getTime()</ code>之类的东西作为远程应用程序不使用的参数名称的值。</ p>

这会欺骗,即每次都认为它是一个新请求。</ p>

编辑:发现了类似的问题添加 链接。</ p>

答案比我做得更好,解释得很清楚,它还包含一个jquery解决方案。
(从链接的答案中复制,因此信誉就可以得到。)</ p>

  $。ajaxSetup({cache:false});
</ code> </ pre>
     </ div>

展开原文

原文

With ie you'll need to append some kind of random parameter to your request.

I typically use something like (new Date()).getTime() as the value for a parameter name that is not used by the remote application.

This will trick ie into thinking it's a new request every time.

Edit: Found a similar question adding link.

This answer does a better job of explaining it than I do, it also has a jquery solution included. (copied from the linked answer so credit goes there.)

$.ajaxSetup({ cache: false });

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