I am trying to send json data to an API but it is returning status code 0. I get this error message in the console: "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at asm-resumator.azurewebsites.net/resumes. (Reason: CORS header 'Access-Control-Allow-Origin' missing)."
Can you please point out what is wrong or missing with my following code:
var candidate= {name :"Wedad",email:"myemail", phoneNumber:"1234567", resume:"myresume"
};
$.ajax({
type: "POST",
data :JSON.stringify(candidate),
url: "url",
dataType: 'json',
success: function (data) {
alert(data);
},
error: function (jqXHR, exception) {
var msg = '';
if (jqXHR.status === 0) {
msg = 'Not connect.\n Verify Network.';
} else if (jqXHR.status == 404) {
msg = 'Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + jqXHR.responseText;
}
alert(msg);
}
});