Skip to main content

Bug Tracker

Side navigation

#8146 closed bug (fixed)

Opened February 02, 2011 05:42PM UTC

Closed February 03, 2011 02:03AM UTC

Last modified February 06, 2013 04:48PM UTC

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

Attachments (0)
Change History (15)

Changed February 02, 2011 05:50PM UTC by rwaldron comment:1

cc: → jaubourg
component: unfiledajax
owner: → shreddd
priority: undecidedlow
status: newpending

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.

Changed February 02, 2011 06:38PM UTC by jaubourg comment:2

keywords: → regression
milestone: 1.next1.5.1
owner: shredddjaubourg
priority: lowhigh
status: pendingassigned

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.

Changed February 02, 2011 08:17PM UTC by jaubourg comment:3

resolution: → fixed
status: assignedclosed

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

Changed February 02, 2011 08:21PM UTC by jaubourg comment:4

shreddd, can you confirm your issue is solved if you set the xhrFields option, using git0?

Sample code:

$.ajax({
   xhrFields: {
      withCredentials: true
   }
});

git0: http://code.jquery.com/jquery-git.js

Changed February 03, 2011 01:04AM UTC by shreddd comment:5

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 [comment:4 jaubourg]:

shreddd, can you confirm your issue is solved if you set the xhrFields option, using git0? Sample code:
> $.ajax({
>    xhrFields: {
>       withCredentials: true
>    }
> });
> 
git0: http://code.jquery.com/jquery-git.js

Changed February 03, 2011 01:58AM UTC by jaubourg comment:6

resolution: fixed
status: closedreopened

Got it: http://code.google.com/p/v8/issues/detail?id=789

Should be set after the xhr has been opened. On it.

Changed February 03, 2011 01:58AM UTC by jaubourg comment:7

status: reopenedassigned

Changed February 03, 2011 02:03AM UTC by jaubourg comment:8

resolution: → fixed
status: assignedclosed

Fixes #8146. Custom fields in xhrFields are now set after the XMLHttpRequest object has been opened.

Changeset: 823eecab9073b43a283a2500e9e43c3a06cc2495

Changed February 03, 2011 02:04AM UTC by jaubourg comment:9

shreddd: should be all good now :)

Changed February 03, 2011 05:09PM UTC by jaubourg comment:10

keywords: regressionregression, needsdocs

Changed February 03, 2011 09:44PM UTC by shreddd comment:11

Tested on Firefox and Chrome. Appears to be working. Thanks for the excellent response time on the bug fix.

Replying to [comment:9 jaubourg]:

shreddd: should be all good now :)

Changed June 20, 2011 05:52AM UTC by addyosmani comment:12

keywords: regression, needsdocsneededdocs

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/

Changed February 06, 2013 04:35PM UTC by bernhardeckl@gmx.de comment:13

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

}

});

Changed February 06, 2013 04:45PM UTC by anonymous comment:14

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');

});

Changed February 06, 2013 04:48PM UTC by dmethvin comment:15

Please take your debugging progress to the forum, rather than posting on a closed ticket.