8

I've got a site that's using rails3, jquery-forms, and I'm testing in firefox and chome.

For the sake of testing, I've got the server returning 422 status every time.

When I submit my form, Firefox correctly hits "error." Chrome incorrectly hits "success."

Anyone have any ideas why this might be the case?

$('form').ajaxSubmit({
    dataType: 'json',
    success: function(responseText, statusText, xhr, $form) {
        console.log("It hits success");         
    },
    error: function(responseText, statusText, xhr) {
            console.log("It hits failure");
    }
    });
earnold
  • 1,440
  • 1
  • 15
  • 26

1 Answers1

0

I assume that your server code looks like this :

def update
 @model = Model.find(params[:id])
 @model.update_attributes(params[:model])
 if @model.save
   render :json => @model, :status => :ok
 else
   head :unprocessable_entity # aka 422 status code
 end
end

So first of all, is there any file upload involved in your ajax request? Apparently, the HTTP status code cannot be used in that case. topic on JQuery forum

Conditions for a success callback is a 2xx status or 304 (not modified).

basgys
  • 4,320
  • 28
  • 39