I am updating a form and i want to make an update request on the serverwith an id my model is:
var CampaignEditModel = Backbone.Model.extend({
urlRoot:\
Instead of passing options
to your custom render(options)
function and setting the model id
there, set the it directly on the editCampaigns
model, before entering render(options)
:
editCampaigns.set('id', id);
$contents.empty().append(new EditView({model:editCampaigns}).render().el);
and remove the extra
this.model.set({"id":options.id})
from render(options)
together with the options
parameter. It should look like similar to this:
render: function(){
this.$el.append( _.template(EditTemplate));
console.log(this.model.get("id"));
this._modelBinder.bind(this.model, this.el);
return this;
}
Your model also has an extra url
function:
url : function(){
var url = this.urlRoot + this.id;
return url;
}
you don't need this one since the models' id
is automatically appended after urlRoot
.
Unrelated to you problem I see you used
http://localhost:3033/campaign/update
to define your update URL. The HTTP method you use, already says what kind of action will be executed, this is the reason why you can (and should) write URLs without verbs. Just remove the extra /update.
Here is a quick summary about best-practices: How to create REST URLs without verbs?
Double check that the request is a post request and not a put request. 'Failed to load resource' errors is usually related to a missing request handler.