Side navigation
#5866 closed bug (fixed)
Opened January 19, 2010 03:57PM UTC
Closed January 26, 2011 12:45AM UTC
Last modified March 14, 2012 12:49AM UTC
.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 (9)
Changed January 20, 2010 02:33AM UTC by comment:1
Changed January 20, 2010 09:32AM UTC by comment:2
_comment0: | 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:'. → 1294064152218897 |
---|
No i mean an url like
#!text //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:'.
Changed January 22, 2010 01:32PM UTC by comment:3
_comment0: | The simpler fix would be #1. \ \ {{{ \ #!text \ // Use the ActiveXObject everytime when it is available \ xhr: window.XMLHttpRequest && !window.ActiveXObject ? \ function() { \ return new window.XMLHttpRequest(); \ } : \ function() { \ try { \ return new window.ActiveXObject("Microsoft.XMLHTTP"); \ } catch(e) {}; \ } \ }, \ }}} \ \ Can anyone with rigths please add some processor tags in my initial report, I forgot about it. → 1294064026846302 |
---|
Simple fix by ajaxSetup:
#!text // 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(); } });
Changed February 19, 2010 09:23AM UTC by comment:4
_comment0: | \ 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 \ \ And my commits: \ \ http://github.com/skrings/jquery/commit/d6613c18663e439bb962af1799679dcf2f35d44a \ \ http://github.com/skrings/jquery/commit/cd2c6f7d7f792a179fdf8849d808f04dac634a12 \ \ http://github.com/skrings/jquery/commit/b6c7ea639120b40cbabea7752b3fed486d28f7b7 → 1294063689189769 |
---|
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.
Changed November 10, 2010 08:18PM UTC by comment:5
keywords: | → needsreview |
---|---|
priority: | major → low |
Changed December 27, 2010 10:37PM UTC by comment:6
keywords: | needsreview → needsreview,ajaxrewrite |
---|
Changed January 03, 2011 02:06PM UTC by comment:7
jsFiddle for easier review: http://jsfiddle.net/WuGZh/
Changed January 25, 2011 11:44PM UTC by comment:8
milestone: | 1.4.1 → 1.next |
---|---|
owner: | → jaubourg |
status: | new → assigned |
version: | 1.4 → 1.5rc1 |
3rd party pull request
Changed January 26, 2011 12:45AM UTC by comment:9
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
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.