Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending credentials with cross-domain posts?

According to Requests with credentials, Firefox will only send credentials along with cross-domain posts if

invocation.withCredentials = "true";

is set… But it doesn't seem like jQuery's Ajax API provides any mechanism for this.

Is there something I've missed? Is there some other way I can do it?

like image 364
David Wolever Avatar asked Jan 13 '10 04:01

David Wolever


People also ask

How do I send a cross domain request?

Setup your cross domain POST from JS (jQuery example): $. ajax({ type: 'POST', url: 'https://to.com/postHere.php', crossDomain: true, data: '{"some":"json"}', dataType: 'json', success: function(responseData, textStatus, jqXHR) { var value = responseData.

Can I send Ajax request to another domain?

Browser does not allow cross domain AJAX requests due to security issues. Cross-domain requests are allowed only if the server specifies same origin security policy. To enable CORS, You need to specify below HTTP headers in the server.

What is xhrFields?

xhrFields Blockquote. Type: PlainObject. An object of fieldName-fieldValue pairs to set on the native XHR object. For example, you can use it to set withCredentials to true for cross-domain requests if needed.


1 Answers

Functionality is supposed to be broken in jQuery 1.5.

Since jQuery 1.5.1 you should use xhrFields param.

$.ajaxSetup({     type: "POST",     data: {},     dataType: 'json',     xhrFields: {        withCredentials: true     },     crossDomain: true }); 

Docs: http://api.jquery.com/jQuery.ajax/

Reported bug: http://bugs.jquery.com/ticket/8146

like image 148
Kangur Avatar answered Oct 19 '22 20:10

Kangur