I'm trying to make a simple jquery ajax call to API:
My Code:
$.ajax({
origin: "*",
url: 'http://example/test',
type: 'get',
contentType: 'application/json; charset=utf-8',
dataType: 'jsonp',
crossDomain: true,
beforeSend: function (xhr) {
xhr.setRequestHeader("API_KEY", 'xxx');
xhr.setRequestHeader("Authorization", 'xxx');
},
success: function (data) {
});
},
error: function () {
}
});
Api working correctly with authorization and return right data but gives error 403 Forbidden when I called it from JQuery ajax.
Response Header:
HTTP/1.1 403 Forbidden Cache-Control: no-cache Pragma: no-cache Content-Type: text/javascript; charset=utf-8 Expires: -1 Server: Microsoft-IIS/8.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Sun, 19 Mar 2017 13:00:19 GMT Content-Length: 127
Request Headers:
Accept:/ Accept-Encoding:gzip, deflate, sdch Accept-Language:en-US,en;q=0.8 Cache-Control:no-cache Connection:keep-alive Host:sp16-app:2525 Pragma:no-cache Referer:http://xxx/test