PDA

View Full Version : Local JSON file reading.



stirucherai
7 Dec 2011, 11:14 PM
Hi,

Have been trying to read local JSON file (used chrome option --allow-file-access-from-files ) into a store. This used to work pretty well in 1.x. Now in SENCHA TOUCH 2.0 it works only if we deploy on webbrowser but not when we access directly using file://<index.html>

Is there any solution for the same.

I have tried my own code as well some samples like "FrancisShanahan-SenchaTouch2MVCHelloworld-c330be1" --

** This does impact if we use phonegap to compile the code and try on iPad.

Thanks and Regards
Sarang

aacoro
8 Dec 2011, 7:22 AM
relative paths doe not work for you? Like:


../../data.json

rdougan
8 Dec 2011, 4:11 PM
Do you mean in the browser, or PhoneGap? This should work- I've done it several times.

Could you provide a simple testcase so we can look into it?

stirucherai
8 Dec 2011, 8:10 PM
I had just downloaded FrancisShanahan-SenchaTouch2MVCHelloworld-c330be1 from https://github.com/FrancisShanahan/SenchaTouch2MVCHelloworld and copied to the following directory

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Frank

When i use file:///C:/Program%20Files/Apache%20Software%20Foundation/Apache2.2/htdocs/Frank/index.html in CHROME

The second carousel panle which is supposed to show list item DOES NOT SHOW any items. I checked in javascript console -- no error. Also checked the store element and data is empty. Tried using javascript console to load but result is same


When I use http::/localhost/frank/index.html -- everything works perfect (basically apache is running)

THanks and Regards
Sarang

stirucherai
9 Dec 2011, 4:31 PM
Any update please ?

When I directly use (file:// -- without webserver), and set breakpoint on callback this is what I have

records :null
success :false
operation : full details

Thanks and Regards
Sarang

stirucherai
9 Dec 2011, 5:55 PM
On tracing this is what we get

request.xhr.status = 0 when we use file:// (without browser) --
request.xhr.status=200 when we use browser

but both request.xhr.response contains the json file content in both case (with browser or without)

THanks and Regards
Sarang

stirucherai
10 Dec 2011, 3:23 AM
Changed the code from


var success = (status >= 200 && status < 300) || status == 304 ,


to



var success = (status >= 200 && status < 300) || status == 304 || status ==0,


Not sure whether this is right approach.

themightychris
15 Dec 2011, 11:30 PM
I use this patch for AjaxProxy in Sencha 1.x:


Ext.util.Observable.observe(Ext.data.AjaxProxy);
Ext.data.AjaxProxy.on('exception', function(store, response, operation) {
if(response.status == 0)
operation.request.callback.call(operation.request.scope, null, true, response);
});

It listens for requests that fail because status==0 and calls the original callback with success=true

tomyuen007
27 Mar 2013, 6:13 PM
I am trying to read a json file from Sencha Architect Sencha Touch 2 application but getting "MyJsonReader unable to read data. Open in Browser: data/cars.json". I am just trying to read the cars.json file which comes with the example. I posted the question a few times in the Sencha Forum but that did not point me to anywhere that can help me. The odd thing is that I was able to read the cars.json file from the ExtJS app in Sencha Architect.


I think Sencha Architect is the a good product but if I cannot even read a simple json file, I am not convinced it will help me do our system.


Can someone help me so that I can move to the next step in my evaluation process.


Best regards

indranilthatte
17 Oct 2013, 11:04 PM
read the topic http://www.sencha.com/forum/showthread.php?258919-Urgent-help-proxy-load-local-JSON-file&p=1004473&viewfull=1#post1004473

hope this will help you.