forked from GNUsocial/gnu-social
Detect and show AJAX errors on FormXHR submission handling.
Previously we threw away errore reported by the actual AJAX submission and only used whatever error the browser reported to us; this didn't help if we reached the server ok but had a problem there. We now extract the #error if given and use that in the alert(). Also should now show 'Unknown error' instead of a crappy generic 'something died in jQuery' when we get a 200 response but bogus return data.
This commit is contained in:
parent
2bad1d0cd9
commit
7d202e9c61
22
js/util.js
22
js/util.js
@ -253,16 +253,34 @@ var SN = { // StatusNet
|
||||
.attr(SN.C.S.Disabled, SN.C.S.Disabled);
|
||||
},
|
||||
error: function (xhr, textStatus, errorThrown) {
|
||||
alert(errorThrown || textStatus);
|
||||
// If the server end reported an error from StatusNet,
|
||||
// find it -- otherwise we'll see what was reported
|
||||
// from the browser.
|
||||
var errorReported = null;
|
||||
if (xhr.responseXML) {
|
||||
errorReported = $('#error', xhr.responseXML).text();
|
||||
}
|
||||
alert(errorReported || errorThrown || textStatus);
|
||||
|
||||
// Restore the form to original state.
|
||||
// Hopefully. :D
|
||||
form
|
||||
.removeClass(SN.C.S.Processing)
|
||||
.find('.submit')
|
||||
.removeClass(SN.C.S.Disabled)
|
||||
.removeAttr(SN.C.S.Disabled);
|
||||
},
|
||||
success: function(data, textStatus) {
|
||||
if (typeof($('form', data)[0]) != 'undefined') {
|
||||
form_new = document._importNode($('form', data)[0], true);
|
||||
form.replaceWith(form_new);
|
||||
}
|
||||
else {
|
||||
else if (typeof($('p', data)[0]) != 'undefined') {
|
||||
form.replaceWith(document._importNode($('p', data)[0], true));
|
||||
}
|
||||
else {
|
||||
alert('Unknown error.');
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
2
js/util.min.js
vendored
2
js/util.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user