Saturday, August 29, 2009

jQuery.Form and its AJAX file upload gotchas.

Hit a few "gotcha, motherfucker!" moments with jQuery.Form while doing AJAX file uploads:

  • If you return an HTTP error, don't return any text (such as error details) -- it'll be interpreted as a successful call and won't handle your error callback.
  • If you return an HTTP error, don't reply on xhr.status from the error callback -- it'll be an unhelpful 0 for some reason.

Alternatives suck: returning an error code and checking to see what kind of data got returned from the call (is it an 'error' object or a model object?).