Results 1 to 6 of 6

Thread: HELP Canot Load data from php

  1. #1

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

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,410

    Default

    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.

  3. #3

    Default

    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"}]

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,410

    Default

    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'
    	}]
    });
    Code:
    {
    total: 2,
    data: [
            {
                "abbr": "AL",
                "name": "Alabama",
                "slogan": ""
            },
            {
                "abbr": "WY",
                "name": "Wyoming",
                "slogan": ""
            }
     ]
    }
    Regards,
    Scott.

  5. #5

    Default

    thank you scot i try first your code..

  6. #6

    Default

    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,
    storetore,
    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •