Reputation: 13329
Ok, Im using REST Console (Chrome extension) to test a rest API. The requests work with the REST Console, but doing the same in javascript AJAX it fails with Origin localhost:8000 is not allowed by Access-Control-Allow-Origin.
The server is setup to allow *, and I can see this in the REST Console's response headers. But looking at the my response Headers when doing a ajax request in javascript, I see that those headers is not there.
What is the difference between the two?
Here is my simple AJAX request (coffeescript)
$.ajax
type: requestType
contentType: "application/json"
url: url
data: data_string
success: (r) =>
successCallback(r)
error: (r) =>
errorCallback(r)
This works at the office in the local network, now on the VPN it does not. But REST Console always works??
Upvotes: 2
Views: 1147
Reputation: 27443
application/json
is not allowed for Content-Type:
in a simple CORS request.
It has to be preflighted, and the server side setup for that is a bit more complex.
Try unsetting contentType or using one of these, if appropriate:
see also my previous answer here
and a related question:
jQuery CORS Content-type OPTIONS
Upvotes: 3