Allow sending in a function to be run on successful XHR

This commit is contained in:
Zach Copley 2011-04-17 18:36:59 -07:00
parent 8cfb81deac
commit eaca17be58
2 changed files with 9 additions and 2 deletions

View File

@ -236,10 +236,11 @@ var SN = { // StatusNet
* @fixme can't submit file uploads * @fixme can't submit file uploads
* *
* @param {jQuery} form: jQuery object whose first element is a form * @param {jQuery} form: jQuery object whose first element is a form
* @param function onSuccess: something extra to do on success
* *
* @access public * @access public
*/ */
FormXHR: function(form) { FormXHR: function(form, onSuccess) {
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
dataType: 'xml', dataType: 'xml',
@ -274,9 +275,15 @@ var SN = { // StatusNet
if (typeof($('form', data)[0]) != 'undefined') { if (typeof($('form', data)[0]) != 'undefined') {
form_new = document._importNode($('form', data)[0], true); form_new = document._importNode($('form', data)[0], true);
form.replaceWith(form_new); form.replaceWith(form_new);
if (onSuccess) {
onSuccess();
}
} }
else if (typeof($('p', data)[0]) != 'undefined') { else if (typeof($('p', data)[0]) != 'undefined') {
form.replaceWith(document._importNode($('p', data)[0], true)); form.replaceWith(document._importNode($('p', data)[0], true));
if (onSuccess) {
onSuccess();
}
} }
else { else {
alert('Unknown error.'); alert('Unknown error.');

2
js/util.min.js vendored

File diff suppressed because one or more lines are too long