![](/img/trans.png)
[英]Getting JSON parse error while using Childbrowser in Cordova 1.9.0
[英]Cordova 1.9.0 Ajax not retrieving
我一直在遵循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這個和外部主機,但是找不到在哪里添加白名單的服務器...
任何幫助將不勝感激!
您已獲得訪問應用程序內另一個網站的權限。 只需像這樣更改cordava.xml。 要訪問Twitter,
<?xml version="1.0" encoding="utf-8"?>
<cordova>
<access origin="http://search.twitter.com/"/>
<log level="DEBUG"/>
</cordova>
訪問所有網站。
<?xml version="1.0" encoding="utf-8"?>
<cordova>
<access origin="*"/>
<log level="DEBUG"/>
</cordova>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.