1. #1
    Sencha User
    Join Date
    Oct 2007
    Posts
    83
    Vote Rating
    -1
    lenoil is an unknown quantity at this point

      0  

    Default 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.
    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');
           }
        },
        //data : g_dataAgences.agences
        
        proxy: {
          type:"jsonp",
          url:"data/agences.json",
          reader:{
            type:'json',
            rootProperty:"agences"
          }
        }
       
      }
    });
    I run my file directly from file :/ / / mydirectory / myApplication / index.html
    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

  2. #2
    Sencha User
    Join Date
    Aug 2011
    Location
    London
    Posts
    409
    Vote Rating
    18
    digeridoopoo will become famous soon enough

      0  

    Default 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?

    :-)

  3. #3
    Sencha User
    Join Date
    Oct 2007
    Posts
    83
    Vote Rating
    -1
    lenoil is an unknown quantity at this point

      0  

    Default


    you have a file json (sample.json) and you load by launch your page by file://.... ?

    How ?

  4. #4
    Sencha User
    Join Date
    Aug 2011
    Location
    London
    Posts
    409
    Vote Rating
    18
    digeridoopoo will become famous soon enough

      0  

    Default 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()

    :-)

  5. #5
    Sencha User
    Join Date
    Oct 2007
    Posts
    83
    Vote Rating
    -1
    lenoil is an unknown quantity at this point

      0  

    Default


    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 ....

  6. #6
    Sencha User
    Join Date
    Aug 2011
    Location
    London
    Posts
    409
    Vote Rating
    18
    digeridoopoo will become famous soon enough

      0  

    Default 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

  7. #7
    Sencha User
    Join Date
    Oct 2007
    Posts
    83
    Vote Rating
    -1
    lenoil is an unknown quantity at this point

      0  

    Default


    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

  8. #8
    Sencha User
    Join Date
    Oct 2013
    Location
    Pune, Maharashtra, India
    Posts
    3
    Vote Rating
    0
    indranilthatte is on a distinguished road

      0  

    Default


    go through link below
    http://www.sencha.com/forum/showthre...=1#post1004473

    hope this will help you.