【发布时间】:2015-03-14 14:11:21
【问题描述】:
我的控制器代码是这样的:
def update
respond_to do |format|
if refresh_quantity_in_inventory
format.json { render json: { message: "Quantity successfully updated" } }
else
format.json { render json: @errors, status: :unprocessable_entity }
end
end
结束
CoffeeScript 是这样的:
ready = ->
$('#best_in_place_cart_quantity').best_in_place().bind 'ajax:error', (evt, data, status, xhr) ->
alert xhr
alert xhr.status
if (xhr.status == 422)
alert("Inventory count is not enough")
$(document).ready ready
$(document).on "page:load", ready
我也试过ajax:success,但都没有触发回调。我如何捕捉 422?我该怎么办?
$('#best_in_place_cart_quantity').best_in_place().done((data, status, response) ->
alert 'Done handler. HTTP code: ' + response.status
return
).fail (error) ->
alert 'Fail handler. HTTP code: ' + error.status
return
这也不起作用。
【问题讨论】:
标签: jquery ruby-on-rails coffeescript best-in-place