admin管理员组文章数量:1323330
What does a Backbone.js 'Model' expect back from the server after a call to Save()
?
The reason I ask is because I had an issue with the model getting cleared after a call to Save()
. I fiddled around with the model's parse()
method. I found the returning an empty object or null
did not produce this behavior. However, the server was returning some JSON as a "success" message and this information seemed to be overwriting the model:
{
message: 'SUCCESS'
}
What is the "correct" way for the server to respond to a Save()
request from a Backbone model
?
Thanks!
What does a Backbone.js 'Model' expect back from the server after a call to Save()
?
The reason I ask is because I had an issue with the model getting cleared after a call to Save()
. I fiddled around with the model's parse()
method. I found the returning an empty object or null
did not produce this behavior. However, the server was returning some JSON as a "success" message and this information seemed to be overwriting the model:
{
message: 'SUCCESS'
}
What is the "correct" way for the server to respond to a Save()
request from a Backbone model
?
Thanks!
Share asked Aug 25, 2012 at 2:24 Chris DutrowChris Dutrow 50.4k67 gold badges195 silver badges262 bronze badges 1- Thanks for asking this question exactly how I would have. – gfullam Commented Nov 26, 2014 at 19:46
2 Answers
Reset to default 10The server should responde with an HTTP status of 200, most likely, and should return any data that the server generates or updates for the model. Typically, this is only the model's server generated id
field. Any fields that are returned from the server will be applied to the model. So if you send this to the server:
{
foo: "bar"
}
and the server response with this:
{
id: 1, // or some other server generated ID, from a database, etc.
message: "SUCCESS"
}
Your model will end up looking like this:
{
id: 1,
foo: "bar",
message: "SUCCESS"
}
If your model does not need any data updated from the server when the save method is called, then you should return an empty {}
object literal.
Well this question often pop's out here and I have already asked it at SO. Seems adding this to ments is not going to help future questioner hence here is the link to answer and question
Getting started with backbonejs - what should a server return
本文标签:
版权声明:本文标题:javascript - What does a Backbone.js 'Model' expect back from the server after a call to Save()? - Stack Overflo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742139814a2422531.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论