我一直在关注http://wiki.phonegap.com/w/page/42450600/PhoneGap%20Ajax%20Sample上的教程 来构建一个简单的 AJAX 请求。但是我希望看到的结果只是一张空白的白页。
<!DOCTYPE html>
<html>
<head>
<title>PhoneGap Ajax Sample</title>
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript">
function appReady(){
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||ajax.status==0)){
eval('var data = ' + ajax.responseText + ';');
var theResults = data.results;
alert(theResults);
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>
有任何想法吗?我环顾四周,听到 Cordova.plist 这个和 External Hosts that,但找不到添加白名单服务器的位置......
任何帮助将不胜感激!