Posted about 8 years ago. Visible to the public.

jQuery ajax success/done will not run callbacks if request is json but the response is empty (typical 200)

When using

Copy
var onDone = function() { ... } var onFail = function() { ... } var params = { ... } var url = ... $.ajax({ type: 'put', url: url, contentType: 'application/json; charset=utf-8', data: JSON.stringify(params), }) .done(onDone) .fail(onFail);

Always make sure your rails controller returns something:

Copy
if @property.update_attributes(params[:property]) render :json => { :ok => true }, :status => :ok else render :json => { :ok => false }, :status => :unprocessable_entity end

Do not use
head :ok
render :nothing => true, :status => :ok

Or else jQuery won't run his callbacks properly

Owner of this card:

Avatar
Pedro Cunha
Last edit:
about 8 years ago
Posted by Pedro Cunha to HouseTrip Deck
This website uses short-lived cookies to improve usability.
Accept or learn more