【发布时间】:2014-07-12 22:28:04
【问题描述】:
我正在尝试使用 Sencha touch 访问 Web 服务。通过浏览器的 JSONP 调用,一切正常。当我们将应用程序切换到物理设备,并将 JSONP 请求(在真实设备上不再需要)更改为普通的 AJAX 调用时,什么也没有发生.....
解决此问题的正确方法是什么?我们正在使用 PHONEGAP,我认为容器可能有问题,因为调用本身看起来应该是这样(-> 并且正在浏览器中工作,其中不需要 PHONEGAP,因此不包括在内。)
这是我的代码:
-
Ajax-Call for the Mobile(不工作)
// 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 插件也已安装。可能还有一些依赖项丢失或错误 - 什么是寻找的好地方?
提前感谢您的帮助, 丹尼尔
【问题讨论】:
-
为什么不再需要 JSONP 请求?
标签: ajax extjs cordova sencha-touch-2 sencha-architect