的index.html
$(document).ready(function() {
alert("load");
window.EXTERNALLINK.loadExternalLink("http://127.0.0.1:8080/v1/service");
$.getJSON("http://127.0.0.1:8080/v1/service", function() {
alert("success");
})
.success(function() { alert("second success"); })
.error(function() { alert("error"); });
document.addEventListener("deviceready", onDeviceReady, true);
});
function onDeviceReady(){
navigator.notification.alert("PhoneGap is working");
}
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="us.service"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="4" />
<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.ACCESS_WIFI_STATE">
</uses-permission>
<uses-permission android:name="android.permission.BIND_VPN_SERVICE">
</uses-permission>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".portalActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
cordova.xml
<?xml version="1.0" encoding="utf-8"?>
<cordova>
<access origin="http://127.0.0.1:8080/*" />
<log level="DEBUG"/>
</cordova>
我无法使用getjson调用其余服务,以上是我所做的配置。如果要添加其他内容,请告诉我
下面是我的休息服务电话
@Controller
@RequestMapping("/v1")
public class ReportController
{
@RequestMapping(method = RequestMethod.GET,
value = "/service" )
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public String status()
{
return "success";
}
答案 0 :(得分:0)
检查这些是否有效
将访问来源更改为<access origin="*" />
将JSON调用更改为此
$.getJSON("http://127.0.0.1:8080/v1/service?callback=?", function() {
alert("success");
});
同时检查您的http://127.0.0.1:8080/v1/service
是否可以直接从浏览器访问。使用chrome并检查响应数据和相应的数据类型。
答案 1 :(得分:0)
你在手机或模拟器上运行吗? 127.0.0.1可能无法解决。使用计算机的主机名或实际的IP地址。 如果您在手机上运行它,请确保您的手机与计算机位于同一网络上。