1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    31
    Vote Rating
    0
    james_D is on a distinguished road

      0  

    Default Answered: Modify 'Store' to read data from URL instead of local file - Beginner

    Answered: Modify 'Store' to read data from URL instead of local file - Beginner


    I have a PHP code in the server that will return all 'Book' information in the form of a JSON string. The URL is http://localhost/all_books.php

    The following STRORE code, that will load the JSON values from a local file called books.json. What i want it to do is to load the JSON records from the URL http://localhost/all_books.php. How can i modify the code to do so ?

    Code:
    Ext.define('App.store.Book', {
    extend: 'Ext.data.Store',
    model: 'App.model.Book',
    proxy: {
    type: 'ajax',
    url: 'data/books.json'
    }
    });

  2. Have a look at JSONP to load data from another domain.
    http://docs.sencha.com/ext-js/4-1/#!...ta.proxy.JsonP

    Scott.

  3. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,996
    Answers
    664
    Vote Rating
    456
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Have a look at JSONP to load data from another domain.
    http://docs.sencha.com/ext-js/4-1/#!...ta.proxy.JsonP

    Scott.

  4. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    31
    Vote Rating
    0
    james_D is on a distinguished road

      0  

    Default


    I get an error in Firebug, any clue why this is happening ? It says Invalid label and there's an arrow pointing to "id" in the JSON response .
    Code:
    invalid label
    
    {"id":"1","name":"columbus"}
    My store class;

    http://localhost/all_human.php Returns the above JSON
    Code:
    Ext.define('Hum.store.Human',{
        extend:'Ext.data.Store',
        model:'Hum.model.Human',
        
        proxy: {
            type: 'jsonp',
            url : 'http://localhost/all_human.php'
        }
        
    });

    EDIT:

    I need to pass 2 parameters to theall_human.php file. 'countryName' is the parameter. and this PHP file accepts POST. How can i pass parameters from the STORE class?

  5. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,996
    Answers
    664
    Vote Rating
    456
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    My mistake .. are you going to be referencing a cross domain URL ... or will it always be localhost?

    It was my understanding you wanted the qualified domain for accessing data from another location. If this is not the case, is there a problem with using a relative path instead requiring the full url to access a local file?

    Scott.

  6. #5
    Sencha User
    Join Date
    Apr 2012
    Posts
    31
    Vote Rating
    0
    james_D is on a distinguished road

      0  

    Default


    I wanted to access the response from a Cross domain URL, but my program worked when i added the PHP files locally. Thank you.

Thread Participants: 1

Tags for this Thread