PDA

View Full Version : how to get the value in ext.ajax.request



farout
15 Dec 2010, 7:14 PM
heres my code


Ext.Ajax.request({
url : 'action/sessionProcess.php',
params : { action : 'USERTYPE' },
method: 'POST',
success: function ( result, request ) {
Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText);

},
failure: function ( result, request) {
Ext.MessageBox.alert('Failed', result.responseText);
}
});

the response

1

my problem is how can i get or retrieve the "result.responseText"
i tried passing it to a variable but still couldnt retrieve the value ...

am using that value i retrieve for tbar which is something like this


hidden: usertype !=2 ? true : false


Any help is greatly appreciated

Thanks in Advance

darthwes
15 Dec 2010, 10:03 PM
function doSomething(t) {
Ext.MessageBox.alert('Success', 'Data return from the server: ' + t);
}
Ext.Ajax.request({
url : 'action/sessionProcess.php',
params : { action : 'USERTYPE' },
method: 'POST',
success: function ( result, request ) {
Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText);
doSomething(result.responseText);
},
failure: function ( result, request) {
Ext.MessageBox.alert('Failed', result.responseText);
}
});


That what you mean?

proofmoore
16 Dec 2010, 2:54 AM
maybe this one will work

success:function(response){
text= response.responseText;
}

mankz
16 Dec 2010, 2:58 AM
What's your server response?

maje
16 Dec 2010, 3:45 AM
It's depends on your server response, like mankz said. If you're using PHP, you can use something like this:



$response = array("success" => true, "value" => "ooooooooooook");
echo json_econde($response);
And to retrieve the response in ExtJs, you can make something like this:




success:function(response){
var data= response.responseText.data;
alert(data.value);
}

farout
16 Dec 2010, 4:18 AM
hi ...

my server response is 1 coz i only echo 1 in my php

what i did is


success: function ( response ) {
var usertype = response.responseText;
}

but when i start calling usertype variable for the so that if the usertype is 1 the hidden will be true and and if usertype is 2 the hidden will be false


hidden: usertype !=2 ? true : false

but i got an error message saying when calling the usertype variable


usertype is not define

:((

mankz
16 Dec 2010, 4:30 AM
Ok I think I understand what you mean. Where does this code come from, could you post some more context?




hidden: usertype !=2 ? true : false

farout
16 Dec 2010, 4:35 AM
heres the code sir


Ext.Ajax.request({
url : 'action/sessionProcess.php',
params : { action : 'USERTYPE' },
method: 'POST',
success: function ( response ) {

var usertype = response.responseText;
alert(usertype);

},
failure: function ( response ) {
Ext.MessageBox.alert('Failed', response.responseText);
}
});


var visitorlistGrid = new Ext.grid.GridPanel({
id: 'visitor-grid'
,store: visitorlistStore
,columns: [{ header: "visitorid", width: 30, dataIndex: 'visitorid', hidden:true }
,{ header: "Date", dataIndex: 'datevisit', width: 80, align: 'center'}
,{ header: "Time In", width: 70, dataIndex: 'timein', align: 'center'}
,{ header: "Time Out", width: 70, dataIndex: 'timeout', align: 'center'}
,{ id: 'visitor-col', header: "Visitor", width: 190, dataIndex: 'visitorname', align: 'left'}
,{ header: "Contact No.", width: 100, dataIndex: 'contactno', align: 'left'}
,{ header: "Reason", width: 200, dataIndex: 'reason', align: 'left'}
,{ header: "Person To Visit", width: 150, dataIndex: 'employeename', align: 'left'}
,{ header: "Department", width: 150, dataIndex: 'department', align: 'left'}]
,autoExpandColumn: 'visitor-col'
,stripeRows: true
,layout: 'fit'
,loadMask: true
,tbar: [{
text: 'Log Visitor'
,iconCls: 'add'
,hidden: usertype !=2 ? true : false
,handler: function(){
............
}
}]
});

mankz
16 Dec 2010, 4:38 AM
Ok, you'll need to programmatically call some method to update the hidden property. Remember that the ajax request is Asynchronous, so the grid code will execute before your ajax request is complete.



Ext.Ajax.request({
url : 'action/sessionProcess.php',
params : { action : 'USERTYPE' },
method: 'POST',
success: function ( response ) {

var usertype = response.responseText;
Ext.getCmp('test').setVisible(usertype == 2);

},
failure: function ( response ) {
Ext.MessageBox.alert('Failed', response.responseText);
}
});


var visitorlistGrid = new Ext.grid.GridPanel({
id: 'visitor-grid'
,store: visitorlistStore
,columns: [{ header: "visitorid", width: 30, dataIndex: 'visitorid', hidden:true }
,{ header: "Date", dataIndex: 'datevisit', width: 80, align: 'center'}
,{ header: "Time In", width: 70, dataIndex: 'timein', align: 'center'}
,{ header: "Time Out", width: 70, dataIndex: 'timeout', align: 'center'}
,{ id: 'visitor-col', header: "Visitor", width: 190, dataIndex: 'visitorname', align: 'left'}
,{ header: "Contact No.", width: 100, dataIndex: 'contactno', align: 'left'}
,{ header: "Reason", width: 200, dataIndex: 'reason', align: 'left'}
,{ header: "Person To Visit", width: 150, dataIndex: 'employeename', align: 'left'}
,{ header: "Department", width: 150, dataIndex: 'department', align: 'left'}]
,autoExpandColumn: 'visitor-col'
,stripeRows: true
,layout: 'fit'
,loadMask: true
,tbar: [{
text: 'Log Visitor'
,id : 'test'
,iconCls: 'add'
,handler: function(){
............
}
}]
});

farout
16 Dec 2010, 4:44 AM
sir how do i do that? ..

sorry am just new to extjs

mankz
16 Dec 2010, 4:45 AM
Try the code in my last post :), it assigns an 'id' to the button so that you can programmatically access it later via "Ext.getCmp" (get component). On the Button class, you can call setVisible which controls its visibility.

farout
16 Dec 2010, 4:49 AM
yehey.. thanks so much :D:D