I'm using
xhrFields : {
withCredentials: true
}
in jQuery $ajax calls, in order to send session cookies within my queries.
The call gives a correct status code on my apache logs (401/200 depending if the cookie is set), but Firefox always receives a status=0 (i.e. an error in $.ajax()) If I remove this xhrFields section, status code is OK (but cookies are not sent)
Here's the response object I receive in Firefox with the xhrFields setup:
{"readyState":0,"responseText":"","status":0,"statusText":"error"}
My Apache config is CORS-enabled, and also allows Access-Control-Allow-Credentials (here are the corresponding HTTP headers)
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Is there something missing, either in the AJAX call, or on the webserver config?
NB: This works perfectly fine in Chrome
ajax() : $. ajax({ type: 'POST', url: 'page. php', data: stuff, success: function( data ) { }, error: function(xhr, status, error) { // check status && error }, dataType: 'text' });
ajax({ type: "POST", url: 'test. php', data: {"type":"check"}, success: function(response){ alert(response); } }); There can obviously be more key-val pairs in data. In this case your alert should read: "The type you posted is check".
jQuery ajax() Method The ajax() method is used to perform an AJAX (asynchronous HTTP) request. All jQuery AJAX methods use the ajax() method. This method is mostly used for requests where the other methods cannot be used.
You probably have to specify the Access-Control-Allow-Origin header more explicitly than *.
https://developer.mozilla.org/En/HTTP_access_control#Requests_with_credentials says:
Important note: when responding to a credentialed request, server must specify a domain, and cannot use wild carding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With