我在手机间隙,jQuery mobile,HTML5中使用简单的getJSON数据编码制作了一个简单的Android应用程序。该应用程序在浏览器中运行良好但不是在android中。
当谷歌搜索时,我发现android无法连接到互联网。所以我添加了以下内容
<uses-permission android:name="android.permission.INTERNET" />
但仍然我的应用程序没有获取jSON数据..在浏览器中运行良好
我的js文件看起来像
function getMovies(){
var serviceURL = "http://myserver.com/";
alert("TEST"); // THIS WILL WORK ON BROWSER AND APPLICATION
$.getJSON(serviceURL + 'movies.php?jsoncallback=?',null, function(data) {
alert(data.result); // THIS WILLL WORK ON BROWSER
var movies=data.result;
$.each(movies, function(index, movie) {
$('#movielist ul').append(
'<li><div class="image"></div><div class="content">'+
'<div class="moviename">'+movie.movie+'</div>'+
'<div class="moviedetails">Description</div>'+
'</div></li>'
);
});
});
}
我在服务器中的PHP代码看起来像
$sql=mysql_query("SELECT * FROM filims");
$result=array();
$i=0;
while($row=mysql_fetch_array($sql)){
$result[$i]['id']=$row['id'];
$result[$i]['movie']=$row['movie'];
//$result[$i]['image']=$row['image'];
$i++;
}
$output=array();
$output['result']=$result;
$output['error']=0;
echo $_GET['jsoncallback'].'('.json_encode($output).')';
我的AndroidManifest.xml看起来像
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.phonegap.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-sdk android:minSdkVersion="7" />
<uses-feature />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".App"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden"> <intent-filter> </intent-filter> </activity>
</application>
</manifest>
请帮助我,提前致谢
答案 0 :(得分:1)
尝试将myserver.com
或*
添加到ExternalHosts
PhoneGap.plist
选项