Backbone model.destroy() invoking error callback function even when it works fine?

后端 未结 5 1254
不知归路
不知归路 2021-02-05 01:01

I have a Backbone.js model that I\'m trying to destroy when the user clicks a link in the model\'s view. The view is something like this (pseudocode because it\'s implemented in

5条回答
  •  情书的邮戳
    2021-02-05 01:39

    I had this same problem. In my delete method on the server (java), I didn't return anything. Just status 200/OK (or 204/No content). And so the "parsererror" problem was caused by jquery trying to convert the empty response into JSON, which failed (since "json" is the default data type).

    My solution was to use the "text" dataType instead, which can be set in the options:

    model.destroy({ dataType: "text", success: function(model, response) {
      console.log("success");
    }});
    

提交回复
热议问题