Created
November 3, 2011 01:53
-
-
Save paulb777/1335562 to your computer and use it in GitHub Desktop.
Twitter AJAX API call from PhoneGap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>PhoneGap Ajax Sample</title> | |
<script type="text/javascript" src="phonegap-1.1.0.js"></script> | |
<script type="text/javascript"> | |
function appReady(){ | |
var ajax = new XMLHttpRequest(); | |
ajax.open("GET","http://search.twitter.com/search.json?q=phonegap",true); | |
ajax.send(); | |
ajax.onreadystatechange=function(){ | |
if(ajax.readyState===4 && (ajax.status===200||ajax.status===0)){ | |
// alert(JSON.stringify(ajax)); | |
var data = JSON.parse(ajax.responseText); | |
var theResults = data.results; | |
var theHTML = ''; | |
for(var i=0;i<theResults.length;i++){ | |
theHTML += ['<div class="tweet"', | |
'<div class="avatar"> <img src='+theResults[i].profile_image_url+' /></div>', | |
'<div class="tweet_content">', | |
'<h2>'+theResults[i].from_user+'</h2>', | |
'<p>'+theResults[i].text+'</p>', | |
'</div>', | |
'</div>'].join(''); | |
} | |
document.getElementById('main').innerHTML = theHTML; | |
} | |
}; | |
} | |
document.addEventListener("deviceready", appReady, false); | |
</script> | |
<style type="text/css"> | |
.tweet {padding-bottom:5px;} | |
.avatar {float: left; height: 48px; width: 48px;} | |
.tweet_content {margin-left: 60px; min-height: 48px;} | |
</style> | |
</head> | |
<body> | |
<div id="main"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Derived from http://wiki.phonegap.com/w/page/42450600/PhoneGap%20Ajax%20Sample