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

Posted Almost 11 years ago. Visible to the public.

When using

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:

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

[Removed]
Posted by [Removed] to HouseTrip Deck (2013-06-21 10:45)