我正在尝试使用Sencha touch访问Web服务。通过浏览器的JSONP调用,一切正常。当我们将应用程序切换到物理设备,并将JSONP请求(在真实设备上不再需要)更改为普通的AJAX调用时,没有任何反应......
解决这个问题的正确方法是什么?我们正在使用PHONEGAP,我认为容器可能有问题,因为调用本身看起来应该是这样( - >并且在浏览器中工作,不需要PHONEGAP,因此不包括在内。)
这是我的代码:
Ajax-Call for the Mobile(not working)
// 1. When we use this on the DEVICE, it DOESEN'T work.
// It seems, like the call isnt fired at all
// JSONP we don't need here......
alert("Ajax request is send");
Ext.Ajax.request ({
url: Adress_To_Webserver,
method: 'GET',
timeout: 1000,
success: function(response, opts) {
alert("sucess");
//alert(Ext.decode(response.responseText));
//var obj = Ext.decode(response.responseText);
console.dir(obj);
},
failure: function(response, opts) {
alert("error");
}
});
JSONP-浏览器调用(工作)
// 2. If we do the same Call (JSONP) on the BROWSER, it WORKS.
alert("Ajax request is send");
Ext.data.JsonP.request ({
url: Adress_To_Webserver,
timeout: 1000,
callbackKey: "myjson",
params: {
callback: function (jsonData) {
}},
success: function(response, opts) {
alert("sucess");
alert(Ext.decode(response.responseText));
var obj = Ext.decode(response.responseText);
console.dir(obj);
},
failure: function(response, opts) {
alert("error");
}
});
如果有人对这个问题有一个提示/解决方案,那就太棒了 - 就像我提到的那样,我使用sencha架构师来构建一个Android应用程序。带有.apk的Phonegap文件夹是自动创建的,config.xml中的所有权限都已设置。 Phonegap插件也已安装。可能有一些更多的依赖关系缺失或错误 - 什么是寻找的好地方?
提前感谢您的帮助, 丹尼尔
答案 0 :(得分:0)
在我看来,您不会将config.xml文件中的<access>
属性设置为origin="*"
或您需要的任何域。此属性指定phonegap允许您的Web应用访问的所有外部域。
因此,您的config.xml文件应包含以下行:
<access origin="*" />
而不是&#39; *&#39;您可以放置从中检索数据的资源。
有明确的说明如何使用它white list (phonegap)