#8146 closed bug (fixed)
Cross Domain Support broken in jquery 1.5
Reported by: | shreddd | Owned by: | jaubourg |
---|---|---|---|
Priority: | high | Milestone: | 1.5.1 |
Component: | ajax | Version: | 1.5 |
Keywords: | neededdocs | Cc: | jaubourg |
Blocked by: | Blocking: |
Description
Following up on the following posting in the forum: http://forum.jquery.com/topic/is-cross-domain-support-broken-in-jquery-1-5
When I try to make a cross domain request (using CORS), I cannot make requests that need the "withCredentials" flag
The following code seems to ignore the xhr.withCredentials flag.
$.ajax({ url: cross_domain_url, beforeSend: function(xhr) { xhr.withCredentials=true; }, success: function(res, textStatus, xhr) { alert(res); } });
This works with jquery-1.4, but the success handler is never triggered in jquery 1.5. I am using firefox 3.6. Thanks -S
Change History (15)
comment:1 Changed 13 years ago by
Cc: | jaubourg added |
---|---|
Component: | unfiled → ajax |
Owner: | set to shreddd |
Priority: | undecided → low |
Status: | new → pending |
comment:2 Changed 13 years ago by
Keywords: | regression added |
---|---|
Milestone: | 1.next → 1.5.1 |
Owner: | changed from shreddd to jaubourg |
Priority: | low → high |
Status: | pending → assigned |
I can confirm this bug. The withCredentials property is put on the jXHR object and, as such, is not propagated to the native xhr (because the native xhr is completely hidden now).
I think the best course of action (seeing as there may be other fields settable on xhr in the future) is to provide a new option (something like xhrProperties) that would contain a map of properties to set on the xhr after creation.
This would look like this:
$.ajax({ xhrProperties: { withCredential: true } });
Only workaround as of now is to redefine the xhr method in the settings like this:
$.ajax({ xhr: function() { var xhr = $.ajaxSettings.xhr(); xhr.withCredential = true; return xhr; } });
If there is no objection, I'll work on adding this feature into core since it's obviously a regression.
comment:3 Changed 13 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixes #8146 by introducing the xhrFields option with is a map of fieldName/fieldValue to set on the native xhr. Can be used to set withCredentials to true for cross-domain requests if needed.
Changeset: 5ef7ddc4c55f49cb7767bba99975f2c7ea5422d9
comment:4 follow-up: 5 Changed 13 years ago by
shreddd, can you confirm your issue is solved if you set the xhrFields option, using git0?
Sample code:
$.ajax({ xhrFields: { withCredentials: true } });
comment:5 Changed 13 years ago by
Fix confirmed to be working in Firefox.
Fix does not work in Chrome: Line 7211 throws an exception:
xhr[ i ] = s.xhrFields[ i ];
Error: INVALID_STATE_ERR: DOM Exception 11
Replying to jaubourg:
shreddd, can you confirm your issue is solved if you set the xhrFields option, using git0?
Sample code:
$.ajax({ xhrFields: { withCredentials: true } });
comment:6 Changed 13 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Got it: http://code.google.com/p/v8/issues/detail?id=789
Should be set after the xhr has been opened. On it.
comment:7 Changed 13 years ago by
Status: | reopened → assigned |
---|
comment:8 Changed 13 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixes #8146. Custom fields in xhrFields are now set after the XMLHttpRequest object has been opened.
Changeset: 823eecab9073b43a283a2500e9e43c3a06cc2495
comment:10 Changed 13 years ago by
Keywords: | needsdocs added |
---|
comment:11 Changed 13 years ago by
Tested on Firefox and Chrome. Appears to be working. Thanks for the excellent response time on the bug fix.
Replying to jaubourg:
shreddd: should be all good now :)
comment:12 Changed 12 years ago by
Keywords: | neededdocs added; regression needsdocs removed |
---|
Docs were updated during the 1.5.1 sprint, but I've added an example and further notes about 1.5 compatibility with the flag here: http://api.jquery.com/jQuery.ajax/
comment:13 Changed 11 years ago by
It seems that this issue is still not solved. The success function will not get executed.
Here is my code:
jQuery.ajax({
type: 'POST', url: $this.attr('action'), data: $this.serialize(), success: function(data) {
console.log("Success"); alert(data); if(data.redirect){
window.location.href=response.redirect;
}
}, xhrFields: {
withCredentials: true
}
});
comment:14 Changed 11 years ago by
Hm, that’s strange, the fail handler does something. But why fail?
jQuery.ajax({
type: 'POST', url: $this.attr('action'), data: $this.serialize(), xhrFields: {
withCredentials: true },
success: function(data) {
console.log("Success"); alert(data); if(data.redirect){
window.location.href=response.redirect;
}
}
}).fail(function() {
alert('SAdf'); });
comment:15 Changed 11 years ago by
Please take your debugging progress to the forum, rather than posting on a closed ticket.
Thanks for taking the time to contribute to the jQuery project! Please provide a reduced jsFiddle test case to help us assess your ticket!
Additionally, test against the jQuery 0 GIT version to ensure the issue still exists.