【问题标题】:Sencha Ajax call not workingSencha Ajax 调用不起作用
【发布时间】:2014-07-12 22:28:04
【问题描述】:

我正在尝试使用 Sencha touch 访问 Web 服务。通过浏览器的 JSONP 调用,一切正常。当我们将应用程序切换到物理设备,并将 JSONP 请求(在真实设备上不再需要)更改为普通的 AJAX 调用时,什么也没有发生.....

解决此问题的正确方法是什么?我们正在使用 PHONEGAP,我认为容器可能有问题,因为调用本身看起来应该是这样(-> 并且正在浏览器中工作,其中不需要 PHONEGAP,因此不包括在内。)

这是我的代码:

  1. 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"); } });

  2. 浏览器的 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


【解决方案1】:

在我看来,您没有将 config.xml 文件中的 <access> 属性设置为 origin="*" 或您需要的任何域。此属性指定 phonegap 允许您的 Web 应用访问的所有外部域。

因此,您的 config.xml 文件应包含以下行:

<access origin="*" />

您可以放置​​您从中检索数据的资源,而不是“*”。

有明确的说明如何使用它white list (phonegap)

【讨论】:

  • 感谢您的回答。这是我做的第一步,但不幸的是它并没有解决问题。我今天会尝试一些事情,如果我有解决方案,我会在这里发布......
猜你喜欢
  • 1970-01-01
  • 2023-03-16
  • 1970-01-01
  • 2018-09-28
  • 2013-05-24
  • 1970-01-01
  • 2013-10-08
  • 1970-01-01
相关资源
最近更新 更多