So when the Ajax call returns a JSON reply, I do :
oData = JSON.parse(sReply);
where
var oData = new cData();
function cData() {
this.Email = "";
this.Name = "";
this.test = function () {
alert("lol");
}
}
The problem is, the JSON string only contains the email and the name variables, so when the oData = JSON.parse(sReply) happens, the function test gets overwritten and when I try to call the function it does not exist. Is there a way to avoid this? I may have many functions in there and other variables which I don’t want to transmit through JSON.
oData = JSON.parse(sReply);– This creates a JavaScript object. It doesn’t matter if oData was previously acDataobject…you just re-assigned it.You should be able to take your JSON response and manually assign its properties to an existing
cDataobject:Or you could loop through the properties: