开发者

How to reach local files with an ajax call in phonegap?

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',
                        pro开发者_如何学Pythonxy: {
                            type: 'ajax',
                                  url : 'file://??????/www/routes.json',
                            reader: {
                                type: 'json'
                         }
                    },
                    autoLoad: true
                })


Treat PhoneGap's www directory like you would a directory on your server. You can create as many sub-folders as you like, and you would reference files with relative links.

As YDL mentioned, if you're trying to access index.json and it resides at the root level of the www folder, you would use: index.json. As another example, if you had a sub-folder called data that housed all your json files, you would use: data/index.json.


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);
        }
      });  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜