httpclient not firing onload and readystateevents..
Hi Folks,
I'm building an app with extjs / jquery and trying to use the HTTPClient supplied by titanium.
The request executes and I can see the response text when I examine the object, but it does not fire the onload and onreadystatechange events..any ideas?
CODE
var xhr = Titanium.Network.createHTTPClient();
xhr.timeout = 1000000;
xhr.open("GET","http://www.cnn.com");
xhr.onreadystatechange = function(){
console.log("herer");
}
xhr.onload = function() {
try{
console.log("herer1");
alert(this.responseText);
}catch(e){
console.log("herer2");
alert(e);
}
};
xhr.send();
1 Answer
-
I'm assuming we're looking at Titanium Desktop here, in which case you might want to consider just using the jQuery or ExtJS ajax implementations. You may find them a little easier to work with.
Using the HTTP client, it looks like you might be running into some timing issues - try calling open after assigning the event handlers - I dropped this code into the sandbox and it worked:
<script> var xhr = Titanium.Network.createHTTPClient(); xhr.timeout = 1000000; xhr.onreadystatechange = function(){ alert("herer"); } xhr.onload = function() { try{ alert(this.responseText); }catch(e){ alert(e); } }; xhr.open("GET","http://www.cnn.com"); xhr.send(); </script>