Bug Tracker

Ticket #5059 (closed bug: invalid)

Opened 5 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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

ajax.txt Download (15.5 KB) - added by ooktay 5 years ago.

Change History

comment:1 Changed 5 years ago by ooktay

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

comment:2 Changed 5 years ago by dmethvin

If your proposed solution doesn't handle errors consistently in IE, that seems like a serious drawback.

Changed 5 years ago by ooktay

comment:3 Changed 5 years ago by ooktay

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 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid
Note: See TracTickets for help on using tickets.