#5059 closed bug (invalid)
No error handling for cross site ajax
Reported by: | ooktay | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | ajax | Version: | 1.3.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
For cross site ajax, when remote site is down error handlers are not called. Here is my mod for error handling:
-------------------START line:3473 in v1.3.2
If we're requesting a remote document and trying to load JSON or Script with a GET if ( s.dataType == "script" && type == "GET" && parts
&& ( parts[1] && parts[1] != location.protocol parts[2] != location.host )){
var head = document.getElementsByTagName("head")[0]; var script = document.createElement("script"); script.src = s.url; if (s.scriptCharset)
script.charset = s.scriptCharset;
Error handling on firefox (DOM standard) script.onerror = function(){
jQuery.handleError(s, null, "error"); complete();
};
Handle Script loading if ( !jsonp ) {
var done = false; Attach handlers for all browsers script.onload = script.onreadystatechange = function(){
if ( !done && ( !this.readyState
this.readyState == "loaded" this.readyState == "complete") ) { done = true; Note that IE will call success even when connection is down We can't do anything about it since IE doesn't have a way to tell success(); complete();
Handle memory leak in IE script.onload = script.onreadystatechange = null; head.removeChild( script );
}
};
} else {
script.onreadystatechange = function(){
Error handling for IE: if connection is down, handler is not run, hence window[ jsonp ] is still there
if ( !done && (this.readyState == "loaded" this.readyState == "complete") && window[ jsonp ] ) {
done = true;
Handle memory leak in IE script.onreadystatechange = null; window[ jsonp ] = undefined; try{ delete window[ jsonp ]; } catch(e){} if ( head )
head.removeChild( script );
jQuery.handleError(s, null, "error"); complete();
}
};
}
Use insertBefore instead of appendChild to circumvent an IE6 bug.
This arises when a base node is used (#2709 and #4378). head.insertBefore( script, head.firstChild );
We handle everything using the script element injection return undefined;
}
-------------------END
Attachments (1)
Change History (5)
comment:1 Changed 13 years ago by
comment:2 Changed 13 years ago by
If your proposed solution doesn't handle errors consistently in IE, that seems like a serious drawback.
Changed 13 years ago by
comment:3 Changed 13 years ago by
You're right. I guess having just FF handle errors is out of question :)
I'll check what we can do about IE.
comment:4 Changed 12 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
For cross site ajax, when remote site is down error handlers are not called. I have attached my mod ajax.txt for error handling. Search for "ooktay:"
Regards, ozgur