![](/img/trans.png)
[英]Javascript AJAX call response status 200 OK but error callback is called
[英]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.