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

前端 未结 3 1372
甜味超标
甜味超标 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条回答
  •  时光说笑
    2020-12-31 01:26

    ID should not even exist for a new entry. The issue is in the part you didn't show - in the part where you instantiate, create and populate the model.

    Here is a quote from the Backbone documentation:

    If the model does not yet have an id, it is considered to be new.

    It is clear from your code that you are assigning an id attribute. Your backend should be doing that. And since you are doing it on a client, backbone presumes it it not new, and uses PUT

提交回复
热议问题