I’m just trying to understand just the basic response here. I have an unedited controller method
def update
@ledgeritem = Ledgeritem.find(params[:id])
respond_to do |format|
if @ledgeritem.update_attributes(params[:ledgeritem])
format.html { redirect_to @ledgeritem, :notice => 'Ledgeritem was successfully updated.' }
format.json { head :no_content }
else
format.html { render :action => "edit" }
format.json { render :json => @ledgeritem.errors, :status => :unprocessable_entity }
end
end
end
And my ajax
$.ajax({
type: "PUT",
url: "/ledgeritems/" + id + ".json",
data: $(this).serialize(),
dataType: "json",
success: function (result) {
alert(result);
}
});
My alert never shows, but the item does update. What’s the correct way to read and handle the json response? I know this is a basic question, but I can’t find any examples or information on this.
In your controller, change
to
head :no_contentwould just return the http code 204, which is to signify that there is no content on the page. You do not need this here.