簡體   English   中英

JSONP ajax調用執行錯誤方法,其響應為200 ok

[英]JSONP ajax call executes error method its response is 200 ok

這是我的api,它的響應是200 OK,但是沒有輸入成功方法,我不知道我做錯了什么。 我在服務器端啟用了CORS。

$( document ).ready(function() {
 $.ajax({

  url: 'https://localhost:44300/api/apim/{{Product.Id}}/'+email+'/',
  dataType: 'jsonp',
  success: function(data) {
   alert("success");
    if(data===true){

        $('#subscribe').prop('disabled', true);
        $('#subscribe').text('Is Pending');
    }
    else 
    {

    }
  },
  error: function(err)
  {
  alert("Error");

  },
  type: 'GET'
 });
});

圖片

在此處輸入圖片說明

您說dataType: 'jsonp',但是服務器說content-type: application/json

JSONP是application/javascript因為它不是JSON(在我們擁有CORS之前,繞過相同的原始策略是一種技巧,因為您正在使用CORS,所以毫無意義……好吧,您聲稱您正在使用CORS,但是我不知道在響應中看不到Access-Control-Allow-Origin標頭)。

刪除dataType: 'jsonp'並讓jQuery從content-type響應頭中計算出數據的類型。

暫無
暫無

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

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