簡體   English   中英

請求具有文本/純MIME類型的JSONP

[英]Request JSONP with text/plain MIME Type

我正在嘗試使用JSONP請求另一個域上的feed。 我知道內容類型應該是JSON或JavaScript,但它是文本/純文本,並且我無法控制服務器,因此無法更改標頭。 如何獲得AJAX呼叫才能正常工作?

這是我到目前為止的內容-

function asdf() {
    $.ajax({
        url: "http://example.com/path/to/sharepoint/_vti_bin/listdata.svc/TestCalendar/$count",
        jsonp: "callback",
        dataType: "jsonp",
        contentType: "text/plain",

        // work with the response
        success: function( response ) {
            console.log( response ); // server response
        }
    });
}

如果我只是嘗試一個常規請求,顯然我只會收到CORS錯誤。

XMLHttpRequest無法加載http://example.com/path/to/sharepoint/_vti_bin/listdata.svc/TestCalendar/ $ count。 所請求的資源上沒有“ Access-Control-Allow-Origin”標頭。 因此,不允許訪問來源“ http://example.com ”。 響應的HTTP狀態碼為401。

嘗試在瀏覽器中直接執行您的URL,以確保一切正常
之后,嘗試使用以下JQuery配置:

$.ajax({
        url        : "YOUR_URL",
        dataType   : 'jsonp',
        crossDomain: true,
        type       : 'POST',
        timeout    : 30000, // in milli seconds
        cache      : false
        success:function(response) {
            console.log(response);
        }
    });

暫無
暫無

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

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