2

所以我正在使用backbone.js,并且我正在尝试保存一个模型。在服务器端,我正在为接收到的模型生成一个 GUID,并且我正在返回该 GUID,以便模型在客户端拥有它。

我的功能就是这样

    this.save({},
        {
            success: function (model, response) {
                alert(response);
            },
            error: function (model, response) {
                alert(response)
            }
        });

它将对象发送到服务器,它从帖子中返回我想要的值。它返回一个 ( HTTP/1.1 200 OK) 但它调用错误函数(其中有我正确的返回值)任何想法为什么?

我在控制台中做了以下

JSON.stringify(response)
"{"readyState":4,"responseText":"5dad212e-73bf-4e01-911a-397b81f77022","status":200,"statusText":"OK"}"

所以它正在取回 200 和 guid 但没有成功......我真的不想只使用错误功能,因为这不是应该触发的:p

提前致谢!

4

1 回答 1

3

查看您的resposneText,似乎服务器没有返回可接受的响应 - 不是正确的json对象。使服务器返回响应,例如,

{ 
  "guid" : "id_to_be_returned" //, 
  // and other attributes to be added in the model 
}

并将响应类型设为json。它应该工作。

于 2012-11-08T06:14:37.877 回答