簡體   English   中英

ajax錯誤:資源被解釋為腳本,但以MIME類型text / json傳輸:

[英]ajax error: Resource interpreted as Script but transferred with MIME type text/json:

我正在嘗試使用JSONP從服務器獲取數據,但在控制台中JSONP收到警告

Resource interpreted as Script but transferred with MIME type text/json:

以下是我的ajax電話

var loginData = {
    "strUniqueID" : "123",
    "UserName" : "UserName",
    "Password" : "Password"
};

$.ajax({
    url: http://domain.com,
    type: "POST",
    data: {'data':$.toJSON(loginData)},
    contentType: "text/plain",
    dataType: "jsonp",
    jsonpCallback: 'jsonCallback',
    success: function(data) {
        console.log('Success');
        console.log(data);
    },
    error: function(jqXmlHttpRequest, textStatus, errorThrown) {
        // Display the error.
        console.log('Error: ' + textStatus);
        console.log('Error thrown: ' + errorThrown);
    }
});

由於收到警告,我也收到此錯誤

Uncaught SyntaxError: Unexpected token : 

在Firefox中,顯示為

SyntaxError: missing ; before statement

這是因為我的數據沒有以正確的格式帶回嗎?

如果我使用參數打開URL,則可以正確獲得響應

{"response":"SESSION ID"}

但是我也從ajax調用中得到一個錯誤

Error: parsererror
Error thrown: jsonCallback was not called

我已經花了幾個小時動腦筋,我很沮喪!

我發現了另一個我有幫助的問題

我需要允許服務上的JSONP請求發送回正確的響應

暫無
暫無

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

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