在我的PhoneGap应用程序中,我有以下代码来测试AJAX REST通信:
$( document ).ready(function() {
$("#test").click(function() {
alert("OK");
$.ajax({
type: "GET",
data: {},
url: "http://localhost:8080/test-notifier-web/RegisterServlet",
});
});
});
<div class="row col-centered">
<button type="submit" id="test">Submit</button>
</div>在Chrome中执行这段代码没问题,我在控制台上进行了日志记录,一切正常。当我用cordova build android构建apk并在我的Genymotion设备上测试它时,服务器没有响应。同时,使用Genymotion浏览器通过web进行测试也是可以的。
我用这段代码创建了一个新的空白应用程序,它在apk上运行良好。有人能帮我吗?
这是我的config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="it.paytas.mobile" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name>Paytas Mobile</name>
<description>
A blank PhoneGap app.
</description>
<author email="support@phonegap.com" href="http://phonegap.com">
PhoneGap Team
</author>
<content src="index.html" />
<access origin="*" />
<preference name="DisallowOverscroll" value="true" />
</widget>发布于 2017-01-17 22:55:19
您需要将"allow-intent“元数据添加到config.xml中
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />您需要将Content-Security-Policy元添加到index.html中
<meta http-equiv="Content-Security-Policy" content="default-src 'self' gap://ready file://* 'unsafe-inline' *; style-src 'self' 'unsafe-inline' *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; img-src *">还要确保您已经安装了cordova-plugin-whitelist插件。
https://stackoverflow.com/questions/41699865
复制相似问题