PDA

View Full Version : help load data to forms



rex0098
13 Dec 2009, 7:03 PM
pls. pls. pls.....help me with my code...i've tried many codes and advices other ext users gave me here in the forums but i still cant get my data appear on my texfields...
please tell me what's wrong with my code...

here is my code:


Ext.onReady(function(){

Ext.QuickTips.init();

var form_employee = new Ext.form.FormPanel({
labelAlign: 'left',
width:300,
height:55,
labelWidth: 100,
buttonAlign:'center',
items:
[{xtype:'textfield',
fieldLabel: 'First name',
name:'first_name',
id:'first_name',
width:190
},
{
xtype:'textfield',
fieldLabel: 'Last name',
name:'last_name',
id:'last_name',
width:190
}]
});
form_employee.getForm().load({url:'getdata.php', waitMsg:'Loading'});
form_employee.render(document.body);

});


this is my getdata.php:


<?php
include "conn.php";

$result=mysql_query ("SELECT first_name,last_name FROM names WHERE name_id = '1'") or die (mysql_error ());

$getdata = array();

while ($row=mysql_fetch_object($result))
{
$getdata = $row;
}

echo '{sucess: true, data: ' . json_encode($getdata) . '}';
?>



this is the response of firebug:


{sucess: true, data: {"first_name":"rodel","last_name":"naz"}}

dreamcaster
13 Dec 2009, 8:15 PM
I think you should traverse from your JSON response. Since the response is not an Object you could try to decode it first.


Ext.util.JSON.decode('your JSON response');

Or you could have a separate Ajax request:


Ext.Ajax.request({
url: 'getinfo.php'
,success: function(res, opt){
// load your data
form_employee.load(res.data.data);
}
});