I have created an asp.net web api and hosted it on a public website. Using Postman I am able to post data to this web API, either running on localhost or on the public site. However, when I tried to post data using a sample asp.net web forms application using jquery it doesn't work. When I try the localhost I get this error: {"readyState":4,"status":404,"statusText":"error"}. When I tried the one running on the public site I don't get any response and neither success nor error section in the jquery code is reached. My current jquery code is given below:
function sendJSON(parameters) {
$.ajax({
url: "http://localhost:49918/SendOrder",
type: "POST",
contentType: "application/json;odata=verbose",
headers: { 'Access-Control-Allow-Origin': '*' },
crossDomain: true,
data:jsonData,
dataType: 'JSONP',
success: function (data) {
alert("success");
console.log('success');
},
error: function (data) {
alert("error: " + JSON.stringify(data));
console.error('error');
},
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Bearer 438590.B089699E7990B9ECCA9E58EA823B0A57");
}
});
}
I copied the bearer token from Postman. I have tried without the beforeSend section too.