Skip to main content

Bug Tracker

Side navigation

#1145 closed bug (fixed)

Opened April 25, 2007 06:06PM UTC

Closed July 21, 2007 12:53AM UTC

error callback does not get called for many errors

Reported by: jakecigar Owned by: john
Priority: major Milestone: 1.1.4
Component: ajax Version: 1.1.3
Keywords: Cc:
Blocked by: Blocking:
Description

I assumed (incorrectly) that the error callback would be called for malformed xml. it is not.

I've had to code around this with the complete callback.

I can now catch safari(webkit), firefox 2 & opera 9, I have no idea what IE will do.

var surveyComplete = function(xrh, status){

var xml = xrh.responseXML

if (status!="success")

form.html("<h1>" + status.toUpperCase() + " requesting:<a href='" + url + "'>" + url +"</a></h1>")

.append("<pre>" + xrh.responseText + "</pre>")

else if (!xml) //safari webkit

form.text(xrh.responseText).wrap("<pre></pre>")

.prepend("<h1> broken xml:<a href='" + url + "'>" + url +"</a> </h1>")

else if (xml.hasChildNodes && !xml.hasChildNodes()) // opera

form.text(xrh.responseText).wrap("<pre></pre>")

.prepend("<h1> broken xml:<a href='" + url + "'>" + url +"</a> </h1>")

else if (xml.firstChild.nodeName == "parsererror") //firefox

form.text(xrh.responseText).wrap("<pre></pre>")

.prepend("<h1> broken xml:<a href='" + url + "'>" + url +"</a> </h1>"+ $.xml(xml))

else

surveyProcess(xml)

}

$.ajax({url:url,datatype:'xml',complete:surveyComplete})

Attachments (0)
Change History (3)

Changed May 02, 2007 12:02AM UTC by malsup comment:1

I use similar logic in the Taconite plugin when converting a string to a document:



var ok = doc && doc.documentElement && doc.documentElement.tagName != 'parsererror';


Changed July 21, 2007 12:15AM UTC by john comment:2

description: I assumed (incorrectly) that the error callback would be called for malformed xml. it is not.\ I've had to code around this with the complete callback.\ \ I can now catch safari(webkit), firefox 2 & opera 9, I have no idea what IE will do.\ \ var surveyComplete = function(xrh, status){\ var xml = xrh.responseXML\ if (status!="success")\ form.html("<h1>" + status.toUpperCase() + " requesting:<a href='" + url + "'>" + url +"</a></h1>")\ .append("<pre>" + xrh.responseText + "</pre>")\ else if (!xml) //safari webkit\ form.text(xrh.responseText).wrap("<pre></pre>")\ .prepend("<h1> broken xml:<a href='" + url + "'>" + url +"</a> </h1>")\ else if (xml.hasChildNodes && !xml.hasChildNodes()) // opera\ form.text(xrh.responseText).wrap("<pre></pre>")\ .prepend("<h1> broken xml:<a href='" + url + "'>" + url +"</a> </h1>")\ else if (xml.firstChild.nodeName == "parsererror") //firefox\ form.text(xrh.responseText).wrap("<pre></pre>")\ .prepend("<h1> broken xml:<a href='" + url + "'>" + url +"</a> </h1>"+ $.xml(xml))\ else \ surveyProcess(xml)\ }\ $.ajax({url:url,datatype:'xml',complete:surveyComplete})\ \ I assumed (incorrectly) that the error callback would be called for malformed xml. it is not. \ I've had to code around this with the complete callback. \ \ I can now catch safari(webkit), firefox 2 & opera 9, I have no idea what IE will do. \ \ var surveyComplete = function(xrh, status){ \ var xml = xrh.responseXML \ if (status!="success") \ form.html("<h1>" + status.toUpperCase() + " requesting:<a href='" + url + "'>" + url +"</a></h1>") \ .append("<pre>" + xrh.responseText + "</pre>") \ else if (!xml) //safari webkit \ form.text(xrh.responseText).wrap("<pre></pre>") \ .prepend("<h1> broken xml:<a href='" + url + "'>" + url +"</a> </h1>") \ else if (xml.hasChildNodes && !xml.hasChildNodes()) // opera \ form.text(xrh.responseText).wrap("<pre></pre>") \ .prepend("<h1> broken xml:<a href='" + url + "'>" + url +"</a> </h1>") \ else if (xml.firstChild.nodeName == "parsererror") //firefox \ form.text(xrh.responseText).wrap("<pre></pre>") \ .prepend("<h1> broken xml:<a href='" + url + "'>" + url +"</a> </h1>"+ $.xml(xml)) \ else \ surveyProcess(xml) \ } \ $.ajax({url:url,datatype:'xml',complete:surveyComplete}) \ \
milestone: 1.1.31.1.4
owner: → john
version: 1.1.21.1.3

Changed July 21, 2007 12:53AM UTC by john comment:3

resolution: → fixed
status: newclosed

Fixed in SVN rev [2433].