简体   繁体   English

IE中的跨域jquery ajax请求xDomain请求不起作用

[英]cross domain jquery ajax request in IE with xDomain Request not working

I have used the following code to make a cross domain jquery ajax request in IE with xDomain Request. 我使用以下代码在IE中使用xDomain Request创建跨域jquery ajax请求。

var xdr;  
 var URL=parentDomain+"/chat/getmessagesservlet";

 if (jQuery.browser.msie && window.XDomainRequest) {  

   // Use Microsoft XDR
   var xdr = new XDomainRequest();
    xdr.open("POST", URL + '?to='+chatboxtitle+'&yourName='+myName+'&chatBoxIndex='+tabIncr);
    xdr.onload = function () {
   var dom  = new ActiveXObject("Microsoft.XMLDOM");
   dom.async = false;
  JSON = $.parseJSON(xdr.responseText); 
   if (JSON == null || typeof (JSON) == 'undefined') {
    JSON = $.parseJSON(data.firstChild.textContent);   
   }

    processData(JSON); // internal function
   }; 

   xdr.onerror = function() {
     _result = false;    
    };
   xdr.send();

    } else {
    $.ajax({ 
      type: 'POST', 
       url: URL,   
          processData: true,
          data: {'to':chatboxtitle,'yourName':myName,'chatBoxIndex':tabIncr}, 
           dataType: "json",
          async: false,
          success: function (data) {
            processData(data);   
           }
});

}'

Also i set header on server side as follows: 我也在服务器端设置标题如下:

response.setHeader("Access-Control-Allow-Origin","*");   
response.setHeader("Content-Type","text/plain");
response.setHeader("Access-Control-Allow-Methods"," GET, POST");
response.setHeader("Access-Control-Allow-Headers", "Content-Type"); 

But In IE8 & IE9 it is not working . 但在IE8和IE9中,它无法正常工作。 ResponseText return null or is empty . ResponseText返回null或为空。 i have seen that using jQuery 我已经看到使用jQuery

.ajaxTransport( dataType, handler(options, originalOptions, jqXHR)

or 要么

.ajaxPrefilter( [dataTypes ], handler(options, originalOptions, jqXHR) )

it is possible to make cross domain request.But i don't know how to use this in my code. 可以进行跨域请求。但我不知道如何在我的代码中使用它。 what are the values to be passed in options & originalOptions paramter? options&originalOptions参数中传递的值是什么? please give me guidance to solve this issue. 请给我指导解决这个问题。

这可能有所帮助:

xdr.onprogress = function () { }; //Needed to save IE9 from melting.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM