Backbone model.save() is sending PUT instead of POST

前端 未结 3 1399
甜味超标
甜味超标 2020-12-31 00:56

I call save using this:

console.log(this.model.isNew());
console.log(this.model);

this.model.save({}, {
    success: function (model, response, options) {
          


        
3条回答
  •  萌比男神i
    2020-12-31 01:51

    The above answers are correct in that if the model you are .save'ing has an id attribute backbone will do a PUT rather than a POST.

    This behavior can be overridden simply by adding type: 'POST' to your save block:

    var fooModel = new Backbone.Model({ id: 1});
    
    fooModel.save(null, {
      type: 'POST'
    });
    

提交回复
热议问题