#5866 closed bug (fixed)
.ajax() fails in IE7 when using an absolute url without protocol
Reported by: | skrings | Owned by: | jaubourg |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | ajax | Version: | 1.5rc1 |
Keywords: | needsreview, ajaxrewrite | Cc: | |
Blocked by: | Blocking: |
Description
From jQuery 1.3.2 to 1.4 the detection of the XHR object has changed. In 1.3.2 every IE uses the ActiveXObject if available. In 1.4 every IE uses the ActiveXObject only if the location protocol is 'file:'.
This causes a problem in IE7, because in IE7 the implementation of XMLHttpRequest is a little bit buggy and in IE8 it seems ok. When you open a new XHR in IE7 with an absolute URL with a protocol and use the XMLHttpRequest object it fails with an error: 'Access is denied'.
IE7 with XMLHttpRequest: fails | IE7 with ActiveXObject : ok
IE8 with XMLHttpRequest: ok | IE8 with ActiveXObject : ok
Take a look at the attached test case, just upload it to any webserver.
Suggested fix #1:
Change the XHR handling so every IE uses the ActiveXObject if available.
Suggested fix #2:
Look for absolute URLs bevore opening the XHR and add a missing protocol.
Suggested fix #3:
Extend the XHR handling so that every IE uses the ActiveXObject if available and the protocol is missing or 'file:'.
Possibile solution:
I would prefer fix #3, so here is my fix which is also inlcuded in the test case. The file is named jquery-1.4.fix.js, just compare it with the 1.4 tag. One problem i have is that i cannot differentiate IE7 and IE8 by the used object. So if the protocol is missing or 'file:' the IE8 will use the ActiveXObject also.
Best regards,
Sören
Some code:
Extended XHR handling
xhr: window.XMLHttpRequest && !window.ActiveXObject ?
function() {
return new window.XMLHttpRequest();
} : function(protocol) {
if (window.XMLHttpRequest && protocol !== "file:" && protocol !== true) {
return new window.XMLHttpRequest();
} else {
try {
return new window.ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {};
}
},
Create the request object
var xhr = s.xhr(protocol);
Attachments (2)
Change History (11)
Changed 13 years ago by
Attachment: | ie7test.zip added |
---|
comment:1 Changed 13 years ago by
So do you mean that when it fails the url is something like "http://something.com/test.htm" and the requesting page is at something.com? An example would help.
comment:2 Changed 13 years ago by
No i mean an url like
//something.com/test.htm
so the request handler (XMLHttpRequest or ActiveXObject) should add the current protocol like 'http:' or 'https:'.
Please take a look at the test case, i log the used url to the console.
The interest is the changed XHR handling from 1.3.2 to 1.4. At this point the api documentation is out of date. http://api.jquery.com/jQuery.ajax/ "Defaults to the ActiveXObject when available (IE)" In 1.4 the ActiveXObject is used only if the protocol is 'file:'.
comment:3 Changed 13 years ago by
Simple fix by ajaxSetup:
// Use the ActiveXObject everytime when it is available $.ajaxSetup({ xhr: !!window.ActiveXObject ? function(){ try { return new window.ActiveXObject("Microsoft.XMLHTTP"); } catch(e){} } : function(){ return new XMLHttpRequest(); } });
comment:4 Changed 13 years ago by
I have attched an updated test case and landed a fix for the problem. It would be glad if someone could review my commits.
See my version here:
http://github.com/skrings/jquery/blob/master/src/ajax.js
Edit: Removed git links.
comment:5 Changed 12 years ago by
Keywords: | needsreview added |
---|---|
Priority: | major → low |
comment:6 Changed 12 years ago by
Keywords: | ajaxrewrite added |
---|
comment:8 Changed 12 years ago by
Milestone: | 1.4.1 → 1.next |
---|---|
Owner: | set to jaubourg |
Status: | new → assigned |
Version: | 1.4 → 1.5rc1 |
3rd party pull request
comment:9 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixes #5866. Issue number in previous commit was wrong both in comments and commit message. See https://github.com/jquery/jquery/commit/0e5b341cc0f3f9bf0f6659e09704f2267cfdfdba for previous commit.
Changeset: d7d64713a72c67243b279b9dcb16ae9fbb825c17
Test case and possible fix included.