-
15 Jan 2013 2:51 AM #1
Load json without web server
Load json without web server
Hi,
by necessity, I have to load json file (GeoJSON) for my application
but without web server. It is more flexible than writing javascript files
with variables containing json data.
I tried but it does not work.
I run my file directly from file :/ / / mydirectory / myApplication / index.htmlCode:Ext.define('PAP.store.Agences', { extend: 'Ext.data.Store', //id:"storeAgence", config: { storeId:"storeAgence", //autoLoad:true, model: 'PAP.model.Agences', sorters: 'name', grouper: { groupFn: function(record) { return record.get('name'); } }, //data : g_dataAgences.agences proxy: { type:"jsonp", url:"data/agences.json", reader:{ type:'json', rootProperty:"agences" } } } });
in the google chrome but it does not works.
I want to copy my application under Android tablet.
How?
Is this possible?
Do you have an example?
To your eyes, what's the better solution?
Thank you for your help
-
15 Jan 2013 5:21 AM #2
JSONP?
JSONP?
I load local JSON no problem....looks like your using JSONP though which is for cross domain requests. Have you tried just normal JSON?
:-)
-
15 Jan 2013 7:23 AM #3
you have a file json (sample.json) and you load by launch your page by file://.... ?
How ?
-
15 Jan 2013 8:48 AM #4
Have a look here....
Have a look here....
Take a look here, you need to use AJAX in your proxy type and not JSONP. JSONP is for cross domain requests, AJAX is for files on the same domain as your app.
http://docs.sencha.com/touch/2-0/#!/api/Ext.data.reader.Json
I just have my JSON file locally in the root of my projects then in the URL i put /presenters.json
Check your console in your browser for any errors or where it is looking for the file (right-click inspect elements, console).
If you are still not seeing data try autoload: true on your store, or make sure you call load on your store when you need it (mystore.load()
:-)
-
23 Jan 2013 6:22 AM #5
sorry for the late
my code in the store
Code:Ext.define('PAP.store.Agences', { extend: 'Ext.data.Store', //id:"storeAgence", config: { storeId:"storeAgence", autoLoad:true, model: 'PAP.model.Agences', sorters: 'name', grouper: { groupFn: function(record) { return record.get('name')[0]; } }, proxy: { type:"ajax", url:"data/agences.json", reader:{ type:'json', rootProperty:"agences" } } } });
if I launch my application with http://.... it's work. I see in my list view my agences.
If I launch my application with file:///..../index.html it doesn't work. The message in the console
XMLHttpRequest cannot load file:///...../data/agences.json?_dc=1358950604573&page=1&start=0&limit=25. Origin null is not allowed by Access-Control-Allow-Origin.
Do you have a solution because i have to work with no web server.
Thanks ....
-
23 Jan 2013 7:12 AM #6
Sorry I misunderstood
Sorry I misunderstood
Sorry I misread the question, I load my local JSON file but I use a webserver when testing locally without an internet connection. Sorry about that.
Perhaps someone else here can answer the question? I did see this post, perhaps it is not possible?
http://www.sencha.com/forum/showthre...ing-web-server
-
23 Jan 2013 7:43 AM #7
it does not matter ....

from what I've read this is not possible apparently ....
I will put my javascript json into a variable that is the only solution that I found


Reply With Quote