最近在做項目的時候,測試PC端網頁,在IE9下會失效,不能正常的發送POST請求,經過仔細的排查,發現是IE9下JQuery發送ajax存在跨域問題。
目前有兩種解決方案:
解決方案一:
設置瀏覽器安全屬性,啟用【通過域訪問數據源】選項,如下圖所示:
解決方案二:
調用ajax方法時,設置crossDomain為true,如下圖所示:
<!DOCTYPE html> <html> <head> <title>jQuery CORS in IE7 - IE10</title> <script src="http://code.jquery.com/jquery-xxxx.min.js"></script> <script> $(document).ready(function() { $.ajax({ url: "http://xxxx.php", dataType: "text", async: true, type: 'GET', cache: false, crossDomain: true , success: function(txt) { //TODO } }); }); </script> </head> <body> IE7到IE10使用jQuery跨域!!! </body> </html>