I`m starting a project with backbone.js and as you know, my main problem was to figure out a good pattern of coding. However, I would like to know how is the best way to handle messages from ajax callbacks (save, destroy, fetch) for example on success without setting all on the model
What I wish to do is separate some data from model and handle it not as attributes, like for example on model.save() callback json:
{ message: "Successful post", post: { id: 13, text: "test" } }
Here is the code:
post = new Post({..})
post.save({}, {
success: function(post, xhr) {
data = jQuery.parseJSON(xhr.responseText)
alert(data.message)
}
})
Is there a better way to do it or I have to leave as attribute? Like:
{ message: "Successful post", id: 13, text: "test" }