如何在phonegap中使用ajax调用访问本地文件? [英] How to reach local files with an ajax call in phonegap?

查看:181
本文介绍了如何在phonegap中使用ajax调用访问本地文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码加载一个json文件存储在phonegap(iPhone)项目(通常在www文件夹)的同一目录,我怎么能到达routes.json?我的项目有这个树文件夹:



__ www /



_ _ _index。 html



_ _ _index.json(其中包含此代码)



_ _routes.json *

  store:new Ext.data.Store({
model:'routes',
proxy:{
type:'ajax',
url:'file:// ?????? /www/routes.json',
reader:{
type:'json'
}
},
autoLoad:true
})

p>

解决方案

我认为这是Sencha Touch Ext.data.Proxy实现中的一个错误。我花了几个小时试图得到这项工作,并没有成功。它花了我不到5分钟使用jQuery实现它。

  //初始化商店
new Ext.data .Store(
{
model:Routes,
storeId:Routes,
//代理未使用,但它是必需的配置选项
proxy:{
type:'ajax'
}
});

//使用jQuery.get()填充商店
$ .get('routes.json',
function(data,status,jqXHR){
if(status ==success){
var store = Ext.StoreMgr.get('Routes');
store.loadData(data);
}
} ;


i Have this piece of code for load a json file stored in the same directory of phonegap ( iPhone ) project ( usually in the "www" folder ), how can i reach "routes.json" ?. My project have this tree folder:

__www/

___index.html

___index.json ( where is located this code )

___routes.json*

  store: new Ext.data.Store({
                    model  : 'routes',
                        proxy: {
                            type: 'ajax',
                                  url : 'file://??????/www/routes.json',
                            reader: {
                                type: 'json'
                         }
                    },
                    autoLoad: true
                })

解决方案

I think that this is a bug in the Sencha Touch Ext.data.Proxy implementation. I spent a couple hours trying to get this work and was unsuccessful. It took me less than 5 minutes to implement it using jQuery.

//Initialize the Store
new Ext.data.Store(
  { 
    model: "Routes", 
    storeId: "Routes",
    //The Proxy isn't used but it is a required configuration option
    proxy: {
      type: 'ajax' 
    }
});

//Populate the store using jQuery.get()
$.get('routes.json',
      function(data, status, jqXHR) {
        if(status == "success") {
          var store = Ext.StoreMgr.get('Routes');
          store.loadData(data);
        }
      });  

这篇关于如何在phonegap中使用ajax调用访问本地文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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