jQuery Ajax 422 在 Chrome 中被识别为成功请求

8
我有一个使用Rails 3和jQuery-forms的网站,我正在Firefox和Chrome中进行测试。
为了进行测试,我让服务器每次返回422状态码。
当我提交表单时,Firefox正确地显示“错误”。但Chrome错误地显示“成功”。
有人知道这是什么原因吗?
$('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");
    }
    });

你的操作是什么样子的?你以JSON格式返回响应吗? - Johny
1个回答

0
我假设你的服务器代码看起来像这样:
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

首先,你的ajax请求中是否涉及文件上传?显然,在这种情况下无法使用HTTP状态码。JQuery论坛上的主题 成功回调的条件是2xx状态或304(未修改)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接