Hi all,
I am trying to get an object to be aware of its own changes e.g. have it execute one of its functions but only when a variable has been changed from outside the object.
Google gave me lots of references to XMLHttpRequest.onreadystatechange and this resource at MSDN: http://msdn.microsoft.com/en-us/library/ms536957%28VS.85%29.aspx. However I tried it in the following:
var Register = {
onreadystatechange : function() {
window.alert("The object has changed state");
},
JsonToServer : {
"targetElementId" : "registrationForm",
"message" : "hello"
},
JsonFromServer : {},
Effect : function() {
JsonHttpRequest(this.JsonToServer);
}
}
... and it didn't work. The object itself works fine as after I've set Register.JsonFromServer via XMLHttpRequest() I can access it directly (and before XMLHttpRequest() is called, Register.JsonFromServer just returns a blank object). This to me suggests onreadystatechange isn't implemented by me correctly (but I'm not smart enough to know where I've gone wrong).
I'd be really grateful if someone with more experience could let me know of any workarounds/what I'm doing wrong.
Thanks in advance for any help/tips/pointers.