PDA

View Full Version : Modify 'Store' to read data from URL instead of local file - Beginner



james_D
30 Jun 2012, 1:11 PM
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 ?


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

scottmartin
30 Jun 2012, 3:06 PM
Have a look at JSONP to load data from another domain.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.proxy.JsonP

Scott.

james_D
30 Jun 2012, 9:28 PM
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 .

invalid label

{"id":"1","name":"columbus"}
My store class;

http://localhost/all_human.php Returns the above JSON


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?

scottmartin
1 Jul 2012, 12:01 PM
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.

james_D
2 Jul 2012, 1:55 AM
I wanted to access the response from a Cross domain URL, but my program worked when i added the PHP files locally. Thank you.