I am trying to create my own XMLHttpRequest structure to find out how this works internally. What puzzles me is that I cannot find how to catch the exception of "the same origin."
The idea is that I am trying to load the URL, if I get the Original origin exception, I re-request the URL through the proxy script local to the script. The reason I do this is because I need to get production data from the sandbox, and I want it to be as transparent as possible for the script itself.
I know this is bad practice, but this is the least intrusive way to do it at the moment :)
Just to clean things up - I don't want to get around the same origin, I just want to catch an abandoned exception so that I can do something about it.
Here is the code I use for my xhr:
var net = function (url, cb, setts){
this.url = url;
this.cb = cb;
var oThis = this;
if (!this.xhr) {
this.xhr = new XMLHttpRequest();
this.xhr.onreadystatechange = function() {
if (oThis.xhr.readyState == 4 && oThis.xhr.status == 200) {
document.body.innerHTML += "RS: "+oThis.xhr.readyState+"; ST:"+oThis.xhr.status+"; RP:"+oThis.xhr.responseText+"<br>";
}
else {
document.body.innerHTML += "RS: "+oThis.xhr.readyState+"; ST:"+oThis.xhr.status+"; RP:"+oThis.xhr.responseText+"<br>";
}
}
}
this.xhr.open("GET", url,true);
this.xhr.send();
}
I tried to try ... catch xhr.send (); but to no avail, they still cannot catch exceptions.
Any ideas or pointers would be greatly appreciated.
bisko source
share