【发布时间】:2016-12-20 08:39:27
【问题描述】:
我有使用 html + javascript (jquery) 制作的 Android Phonegap 构建应用程序。昨天它工作得很好。今天 ajax 调用不再执行。示例代码:
$(document).ready(function(){
setTimeout(function(){
$.ajax({
url: urlPrefix + "/xxxxx",
dataType: "jsonp",
jsonpCallback: "indexCallback"
});
alert('Ajax praejo');
},2000);
});
function indexCallback(response) {
alert('callback prasideda');
}
显示 ajax 调用后的警报,但未出现 indexCallback 函数中的警报。 Ajax 调用外部后端服务器。我已经在后端服务器中记录了呼叫,但没有出现呼叫。
我试图在ajax调用之前超时,但没有结果。
我在 config.xml 文件中列出了所有可能的域:
<plugin name="cordova-plugin-whitelist" version="1" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
<allow-navigation href="data:*" />
当我将 index.html(对外部后端的 ajax 调用)文件加载到桌面浏览器时,一切正常。 有什么想法吗?
【问题讨论】:
-
嗯,我正在将 html/css/js 文件上传到 phonegap 构建中。在构建应用程序并在安卓手机中运行时。
-
去掉 jsonpCallback 的引号
-
它在没有任何变化的情况下开始工作......
-
似乎是 Wifi 问题。使用移动数据时一切正常,但使用 WIFI 应用程序时无法正常工作。
标签: android jquery ajax cordova