jquery ajax 422 coming in as a success in chrome
Asked Answered
B

1

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");
    }
    });
Bascule answered 17/8, 2011 at 21:54 Comment(1)
What does your action looks like, do you render response as json?Washerwoman
C
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).

Collogue answered 23/6, 2012 at 9:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.