簡體   English   中英

跨域的jQuery AJAX適用於Chrome等,但在IE10中不發送數據,在IE <= 9中不發送請求

[英]jQuery AJAX over cross domain working fine for Chrome etc but not sending data in IE10 and not sending request in IE <= 9

在我的Web應用程序中,我需要將數據發送到其他域上托管的API,API處理接收到的數據,然后jQuery AJAX處理API的響應。

此調用在Chrome和Firefox上運行正常,但不適用於IE。 AJAX正在IE10中調用API,但是沒有數據隨調用一起發送。 我添加了put_file_contents(fileName,ReceivedData)來檢查API是否接收到任何數據。 正在創建文件,但它為空白。 AJAX甚至沒有為IE <= 9調用API(未創建文件,並且執行了ajax調用的錯誤部分)。

碼:

已在AJAX調用之前添加了該腳本以支持IE上的CORS- https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest/blob/master/jquery.xdomainrequest.min.js

jQuery(document).ready(function () {
    jQuery.support.cors = true;
    var link = new String(window.location) + "";
    jQuery.ajax({
        url: 'URL_OF_API',
        type: 'post',
        dataType: 'json',
        data: {
            'variable1' : 'value1',
            'variable2' : 'value2'
        },
        success: function (data) {
           //work on received data
        },
        error: function () {
           //This is executed in case of IE<=9
        }
    });
}); 


請幫忙。 提前致謝!

使用IE開發人員工具進行調試。

如果您顯示以下錯誤消息:

... Request method post was not present in the Access-Control-Allow-Methods list

分析您的響應標題。 您應該會看到以下內容:

Access-Control-Allow-Origin: http://www.yourdomain.com
Access-Control-Allow-Methods: POST

您在哪個域上進行測試?

也許這些鏈接可以為您提供更多幫助:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM