解決jquery ajax在跨域訪問post請求的時候,ie9以下無效(包括ie9)的問題

來源:互聯網
上載者:User

標籤:cto   ajax   get   highlight   http   dex   net   ticket   oct   

最近在做項目的時候遇到一個問題,就是跨域請求ajax的時候ie9以下的瀏覽器不可以訪問,直接執行error裡面的代碼,但是也不報錯,就上網查了查,發現了一個很好用的方法,在這裡記錄一下,也希望可以幫到大家。

第一步:設定瀏覽器安全屬性,啟用【通過域訪問資料來源】選項:

1、選擇Internet選項

2、選擇安全---自訂層級

3、找到其他---通過域訪問資料來源,選擇啟用,然後確定就可以了。

第二步:調用ajax方法時,設定crossDomain為相反的值。原文連結:https://bugs.jquery.com/ticket/12097

<!DOCTYPE html><html lang="en"><head>    <title>jQuery CORS in IE7 - IE10</title>    <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>    <script>        $(document).ready(function () {            $.ajax({                url: "http://dreamfactorysql.cloudapp.net/API/index.php",                dataType: "text",                async: true,                type: ‘GET‘,                cache: false,                crossDomain: true == !(document.all),                success: function (data) {                    alert(data);                }            });        });    </script></head><body>IE7 thru IE10 CORS Example Using jQuery</body>

  

 這樣就可以了。

 

解決jquery ajax在跨域訪問post請求的時候,ie9以下無效(包括ie9)的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.