2013-11-21 72 views
0

我一直很難找到一個好的解決方案。我有一個旨在爲網站提供輔助服務的子域。喜歡暗示性的銷售等,我已經創建了一個代碼,將提交一個阿賈克斯後跟蹤。第二個Ajax調用將抓取HTML,並將其發佈到一個div。這適用於IE10,Chrome,Safari和Firefox。但在IE 7-9中不起作用。跨域Ajax調用子域IE7 +

我發現很多帖子,那半解釋一個解決方案。但似乎沒有爲我工作。有沒有人有處理這方面的經驗?非常感謝幫助。

// TRACKER 
function log() { 
$.ajax({url:"http://sub.differentdomain.com/in/li/", dataType:"html", type:"POST", cache:false, timeout:1000, data:{item:"ITEM1", session:"SESSIONKEY"}}); 
} 

// DISPLAYER 
function getTools() { 
$.ajax({url:"http://sub.differentdomain.com/out/sug/", dataType:"html", type:"POST", cache:false, timeout:6000, crossDomain:true, async:false, beforeSend:function() { 
$("#ccont #selling-tools").html('<div class="boxset" style="width:95%; margin:20px 2%;padding:20px 0.5%; margin-bottom:0;"><img src="loader.gif" align="center" /></div>').show(); 
}, error:function() { 
$("#ccont #selling-tools").html(""); 
}, data:{item:"ITEM1", session:"KEY1"}}).done(function(html) { 
$("#selling-tools").html(html); 
}); 
} 

上實現同樣的結果也將做任何其他的建議...

+0

也許這可以幫助你http://stackoverflow.com/questions/11487216/cors-with-jquery-and-xdomainrequest-in-ie8-9 – ncubica

回答

1

嘗試啓用IE瀏覽器CORS這個腳本,你阿賈克斯之前打電話給你的使用jQuery

if (window.XDomainRequest) { 
    jQuery.ajaxTransport(function(s) { 
     if (s.crossDomain && s.async) { 
      if (s.timeout) { 
       s.xdrTimeout = s.timeout; 
       delete s.timeout; 
      } 
      var xdr; 
      return { 
       send: function(_, complete) { 
        function callback(status, statusText, responses, responseHeaders) { 
         xdr.onload = xdr.onerror = xdr.ontimeout = jQuery.noop; 
         xdr = undefined; 
         complete(status, statusText, responses, responseHeaders); 
        } 
        xdr = new XDomainRequest(); 
        xdr.onload = function() { 
         callback(200, "OK", { text: xdr.responseText }, "Content-Type: " + xdr.contentType); 
        }; 
        xdr.onerror = function() { 
         callback(404, "Not Found"); 
        }; 
        xdr.onprogress = jQuery.noop; 
        xdr.ontimeout = function() { 
         callback(0, "timeout"); 
        }; 
        xdr.timeout = s.xdrTimeout || Number.MAX_VALUE; 
        xdr.open(s.type, s.url); 
        xdr.send((s.hasContent && s.data) || null); 
       }, 
       abort: function() { 
        if (xdr) { 
         xdr.onerror = jQuery.noop; 
         xdr.abort(); 
        } 
       } 
      }; 
     } 
    }); 
} 
+0

謝謝!有效。我注意到它沒有通過POST信息,但仍然讓請求發生。我寫了一個小腳本來切換到GET請求。再次感謝。簡單的答案... – RichardW11