PhoneGap will print out the json from twitter below. However when I use any other url for my ajax.open it just shows a blank screen.
Apologies for messy code layout
<pre>
</head>
<body>
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript">
function appReady(){
}
document.addEventListener("deviceready", appReady, false);
var ajax = new XMLHttpRequest();
ajax.open("GET","http://search.twitter.com/search.json?q=bacon",true);
ajax.send();
ajax.onreadystatechange=function(){
if(ajax.readyState==4 && (ajax.status==200))
{
document.getElementById('main').innerHTML = ajax.responseText;
}
}
</script>
Hello
<div id="main">
</pre>
Using eclipse I created a Webserver and started coding these requests from my localhost and using the code below, minus the phonegap.js in the script tag and it worked fine for calling html from /Test2.html”. I removed the “phonegap.js” because on my local machine its not using phonegap, I did replace it with “Test.js”, which just contains this code, which I obtained from W3school documentation on XMLHttpRequest:
When I try to get my emulator to call /Test2.html it shows a blank screen.Also from my own server I am unable to call twitter json, I expect this due to cross domain protection is back on since im not working with phonegap.
Can anyone tell me why I am unable to view Test2 and other urls using this code on my Emulator.
also does anyone know of any other online jsons available, I tried a google and yahoo ones but they also dont seem to work on either.
function handler() {
if(this.readyState == this.DONE) {
if(this.status == 200 && this.responseXML != null && this.responseXML.getElementById('test').textContent)
{
// success!
processData(this.responseXML.getElementById('test').textContent);
return;
}
// something went wrong
processData(null);
}
}
You might need an “API Key” to access other JSON streams. Twitter does not require such a key.