煎茶触摸2.1原生(机器人)的应用程序没有得到来自遥远的JSON(它适用于PC) [英] Sencha Touch 2.1 native (android) app not getting json from remote (it works on PC)

查看:150
本文介绍了煎茶触摸2.1原生(机器人)的应用程序没有得到来自遥远的JSON(它适用于PC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过观看此视频( http://youtu.be/5F7Gx0创建我的第一个煎茶触摸应用2 -W-M4 ),它具有结构像这样的店铺页面:

I created my first Sencha touch 2 app by watching this video (http://youtu.be/5F7Gx0-W-M4) and it has a store page structured like this:

Ext.define('FirstApp.store.Places',{
    extend:'Ext.data.Store',

    config:{

        autoLoad:true,
        model:'FirstApp.model.Place',
        proxy:{
            type:'ajax',
            url:'https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AIzaSyCFWZSKDslql5GZR0OJlVcgoQJP1UKgZ5U',
            reader:{
                type:'json',
                rootProperty:'results'
            }
        }
    }
})

后的编译软件包工作非常好我的MAC(所有浏览器),但生成的应用程序(我运行它在我的Nexus手机上)的作品,但不收集任何数据(跑煎茶应用打造本土后)从谷歌地图JSON。
任何帮助将是AP preciated

The after-build (after running "sencha app build native") package work very well on my MAC (all browsers) but the generated app (i am running it on my nexus phone) works but doesn't collect any data from the google maps json. Any help would be appreciated

推荐答案

正在使用谷歌地图的地方搜索API参考的例子。当你用代理设置为 AJAX 手机应用程序不能使用此API。基本上,你不能使用你的域之外的任何资源。就像如果你的网站是在 yourdomain.com 并没有 someotherdomain.com ,然后你不能让Ajax请求该 someotherdomain.com yourdomain.com ,除非该域允许你。在这种情况下,您的移动应用程序是没有任何域。你只是加载一个页面中的WebView。

The example you are referring is using google map's place search API. You can not use this API when you build the app for mobile phone with proxy set to ajax . Basically, you can not use any resource that is outside your domain. Like if your site is at yourdomain.com and there is someotherdomain.com, then you can't make ajax request to this someotherdomain.com from yourdomain.com unless that domain allows you to. In this case, your mobile app is not having any domain. You are just loading a page inside webview.

的原因是,AJAX将不能够加载跨源资源。应用程序建立在浏览器上运行,因为我相信你在使用Chrome与 - 禁用 - 网络安全标记。要使用你需要使用JSONP代理CORS工作。这是如果你正在打包移动应用的唯一途径。如果在一个情况下,你自己的服务器(而不是在这种情况下,虽然),那么你可以通过设置相应的头文件,如

The reason is, ajax will not be able to load cross-origin resources. App build works on browsers because I believe you're using chrome with --disable-web-security flag. To work with CORS you need to use JsonP proxy. It's the only way if you're packaging for mobile app. If in a case, you own the server ( not in this context though ) then you can allow CORS by setting appropriate headers like

Access-Control-Allow-Origin: *

Access-Control-Allow-Origin: http://yourdomain.com/resource

尝试设置代理JSONP。

Try setting proxy to JsonP .

这篇关于煎茶触摸2.1原生(机器人)的应用程序没有得到来自遥远的JSON(它适用于PC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆