-
11 Apr 2012 4:23 AM #1
HELP Canot Load data from php
HELP Canot Load data from php
hallo i'm new in extjs i try this code i have problem , i can't load data from PHP can help??
form.html
Code:<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css" /> <script type="text/javascript" src="ext-all.js"></script> <script type="text/javascript" src="form.js"></script> <style type="text/css"> .amarillo{ opacity:50; background:#FFFF99 !important;} .verde{ opacity:50; background:#CCFF99 !important;} #frame{ width:300px; margin:100px auto; } </style> </head> <body> <div id="example-grid"></div> </body> </html> form.js // To play in Firebug uncomment next line // Ext.get(document.body).update('<div id="ext-test"></div>'); // reference local blank image Ext.BLANK_IMAGE_URL = 'resources/images/default/s.gif'; // create namespace Ext.namespace('Test'); // create application Test.app = function() { // do NOT access DOM from here; elements don't exist yet // private variables // private functions // public space return { // public properties, e.g. strings to translate // public methods init: function() { //start grid var proxy = new Ext.data.HttpProxy({url:'data.php'}); var reader = new Ext.data.JsonReader( [ {name: 'Employe_Id' ,mapping: 'Employee_Id'}, {name: 'Employe_Name'} ] ); var store=new Ext.data.Store({ proxy:proxy, reader:reader }); store.load(); var grid = new Ext.grid.GridPanel({ store: store, columns: [{header: "Karyawan Number", width: 270, dataIndex: 'Employe_Id', sortable: true}, {header: "Karyawan Name", width: 270, dataIndex: 'Employe_Name', sortable: true}], renderTo:'example-grid', width:540, height:200 }); //end grid } // end of init }; }(); // end of app Ext.onReady(Test.app.init, Test.app); data.php <?php $link = mysql_pconnect("server", "username", "password") or die("Could not connect"); mysql_select_db("database") or die("Could not select database"); $arr = array(); $result = mysql_query("SELECT page_id,page_name FROM page"); /*while($obj = mysql_fetch_object($rs)) { $arr[] = $obj; }*/ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $myInventory[] = array( 'Employe_Id' => $row['page_id'], 'Employe_Name' => $row['page_name']); } $myData = $myInventory; echo json_encode($myData); //echo json_encode($arr); ?>
-
11 Apr 2012 6:30 AM #2
Are you seeing any data coming from the server? if you enter in the URL manually, do you see a JSON string?
How are you debugging your app?
Regards,
Scott.
-
11 Apr 2012 7:00 AM #3
yes if I hit data.php manualy, i get this data
[{"Employe_Id":"1","Employe_Name":"report.php"},{"Employe_Id":"2","Employe_Name":"listArtikel.php"},{"Employe_Id":"3","Employe_Name":"artikelDetail.php"},{"Employe_Id":"4","Employe_Name":"content.php"},{"Employe_Id":"5","Employe_Name":"banner.php"},{"Employe_Id":"21","Employe_Name":"editBanner.php"},{"Employe_Id":"26","Employe_Name":"dbdeals_c2.php"}]
-
11 Apr 2012 7:13 AM #4
You are missing a few properties in your model/store proxy and your JSON is not formatted with these values.
You can create the model or specify in your store.
Code:Ext.define('model', { extend: 'Ext.data.Model', idProperty: 'abbr', fields: [{ name: 'abbr' }, { name: 'name' }, { name: 'slogan' }], proxy: { type: 'ajax', actionMethods: 'POST', url: 'server.php', reader: { type: 'json', root: 'data', totalProperty: 'total' } } }); store = new Ext.data.Store({ autoLoad: true, // also tested false using button to load type: 'json', model: 'model', pageSize: 10, remoteSort: true, sorters: [{ property: 'abbr', direction: 'ASC' }] });Regards,Code:{ total: 2, data: [ { "abbr": "AL", "name": "Alabama", "slogan": "" }, { "abbr": "WY", "name": "Wyoming", "slogan": "" } ] }
Scott.
-
11 Apr 2012 5:33 PM #5
-
12 Apr 2012 1:15 AM #6
i already change my script
store = new Ext.data.JsonStore({
id: 'myStore',
url: "/HITCORP/xjs2/results.json",
autoLoad:true,
method:'GET',
root: 'data',
baseParams: 'sasa:ppp',
fields: ['Employe_Id','Employe_Name']
});
//store.load();
var grid = new Ext.grid.GridPanel({
//store: store,
store
tore,
columns: [{header: "Karyawan Number", width: 270, dataIndex: 'Employe_Id', sortable: true},
{header: "Karyawan Name", width: 270, dataIndex: 'Employe_Name', sortable: true}],
renderTo:'example-grid',
width:540,
height:200
});
and results.json
{"data":[{"Employe_Id":"1","Employe_Name":"report.php"},{"Employe_Id":"2","Employe_Name":"listArtikel.php"}]}
why still not work this code


Reply With Quote