PDA

View Full Version : how to handle the response of a submit ?



Pho
3 Aug 2010, 11:06 AM
Hello all,
i started a few days ago to play with ext :> but now i stucked.

I submit some values and check if they exist inside my data base.
If they exist I get the whole data record and send them + success-msg back to ext.

Here is were i stuck... i don't know how to handle the response (as example: fill a grid with that data).
Tried to find something in the docs but it hard to find something if you don't even know what your looking for

A tiny senseless example to show what I like to do


Ext.onReady(function(){
var myData = [
['****', '*****'],
['####','#####']
];

var store = new Ext.data.ArrayStore({
fields: [
{name: 'stuff',type: 'string'},
{name: 'stuff2', type: 'string'}
]
});

store.loadData(myData);


var grid = new Ext.grid.GridPanel({
store: store,
colModel: new Ext.grid.ColumnModel({
defaults: {
width: 120
},
columns: [
{header: 'data1',dataIndex: 'stuff'},
{header: 'data2',dataIndex: 'stuff2'}
]
}),
viewConfig: {
forceFit: true
},
height: 100,
width: 300
});

var myform = new Ext.FormPanel({
name: 'myform',
width: 350,
frame: true,
defaults: {width: 230},
defaultType: 'textfield',
items: [{
fieldLabel: 'send data',
name: 'data1'
},{
fieldLabel: 'send more data',
name: 'data2'
},grid],

buttons: [{ text: 'send',
listeners: {click: function(){

myform.getForm().submit({
url: 'response.php',
success: function(form, action) {
console.info(action.result.data);
// grid.getStore().loadData(action.result.data); //tried something like that
}
});
}}
}]
});
myform.render(document.body);
});
<?php
$data = array (
'data1' => $_POST['data1'] ,
'data2' => $_POST['data2']
) ;
echo json_encode(array( 'success'=> true,
'data' => $data));
?>Hope you can give me a small hint ;)

thnx in advance

madkris
3 Aug 2010, 4:20 PM
var store = new Ext.data.JsonStore({
root : 'data',
fields: [
{name: 'stuff',type: 'string'},
{name: 'stuff2', type: 'string'}
]
});


<?php
$data = array (
'stuff' => $_POST['data1'] ,
'stuff2' => $_POST['data2']
) ;
echo json_encode(array( 'success'=> true,
'data' => $data));
?>

Try.