Here is the JSON Object which i need to form.
{
"Header1": {
"Login": {
"SiteId": "",
"UserName": "",
"UserPassword": "",
"UserAlias": ""
},
"Credential": {
"Login": "",
"Password": ""
}
},
"Header2": {
"DestinationID": "",
"UserID": "",
"SourceID": ""
}
}
On the click of login, i need to form this JSON and send to my service using backbone.js. I am just confused on where to form this in backbone.js
var Client = Backbone.Model.extend({
defaults: {
}
});
Should i add my JSON Object to defaults and use them?
The backbone model usually relates to a model or db table on the server side. With this in mind you can use @model.set(attributes) to set the value in the model and then use @model.save to send to the server. If you are storing objects on your server model just define them in backbone before setting in the model.
If this is not the case and the model doesn’t correspond to a model or table on the server you might be better off just using JQuery Ajax call and manually construct the JSON you need as above. Hope this helps.