Ahmed Jalal Ahmed Jalal - 5 months ago 28
Ajax Question

JSONP ajax call executes error method its response is 200 ok

Here is my api calling its response is 200 OK but it not entered into the success method I have no clue where i am doing wrong. I enable CORS on server side.

$( 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'
});
});


Image



enter image description here

Answer

You said dataType: 'jsonp', but the server said content-type: application/json.

JSONP is application/javascript because it isn't JSON (it's a hack to get around the same origin policy from before we had CORS, since you are using CORS, it is pointless … well, you claim you are using CORS, but I don't see an Access-Control-Allow-Origin header in the response).

Remove dataType: 'jsonp' and let jQuery work out the type of data from the content-type response header.

Comments