Reputation: 32269
I need to make an ajax POST request (json) to a different domain (later everything will be in the same domain, but I'm testing in localhost and don't have access to the server yet).
Note: Currently there's not possible to make modifications in the server's code.
I found few solutions for this problem:
jsonp: Doesn't work
CORS plugin for firefox (to force allowing different domains): Would work if I send POST request, but JQuery itself is making first OPTIONS request (because it detects different domains, probably). And here I have a problem, because the server needs authentication (for everything, including OPTIONS).
I am sending the authentication in the header of the POST request, but JQuery is not including this in the header of the OPTIONS request, and since it's being done "in the background", I can't add it.
Actually there could be 2 solutions:
Add authentication header to the OPTIONS request. But as mentioned I'm not sending this request myself, so I don't know where/how to do it.
Force JQuery to not make that OPTIONS request, but send POST directly (which is the title of this thread). I searched a while but didn't find anything. Is that possible?
I'm using JQuery 1.7.1 and $.ajax({...}) to make the request.
Thanks in advance.
Upvotes: 0
Views: 2212
Reputation: 14863
This is a tricky one. I suggest doing the following.
Make a ajax-connection a file on the same domain. Do a cURL-connection to the file located somewhere else.
Send post-information and add authentication headers too.
You can see here for the last part: http://php.bigresource.com/CURL-and-HTTP-Authentication--p8WkKqkq.html
Simply googling "post headers curl" should help you with that part.
Upvotes: 1