View Full Version : tbText updating from variable

10 Sep 2009, 9:00 PM
Hey all,

I'm trying to display the username from the php session variables in a toolbar text component, using the following code.

It doesn't seem to work, the variable userFullName is not populated with the username from teh variable.

// topmenu.js
// ExtJS
var userFullName;
url : 'scripts/jsonCalls.php' ,
params : { action : 'userDetails' },
method: 'GET',
success: function ( result, request ) {
Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText);
userFullName = result.responseText;
failure: function ( result, request) {
Ext.MessageBox.alert('Failed', result.responseText);
// Create the toolbar
new Ext.Toolbar({
name: 'topMenu',
renderTo: 'topmenu',
items: [{
xtype: 'tbbutton',
text: 'File',
menu: [{
text: 'Get XML',
icon: 'img/silk/script_code.png'
text: 'Logout',
icon: 'img/silk/door_in.png',
handler: function(){
title: "Logout",
msg: "Are you sure you wish to logout from Triton? Any unsaved changes will be lost",
icon: Ext.MessageBox.WARNING,
buttons: Ext.MessageBox.YESNO,
fn: function(btn){
if (btn == "yes"){
var logout = "scripts/jsonCalls.php?action=logout";
window.location = logout;
xtype: 'tbfill'
xtype: 'tbtext',
name: 'userText',
text: userFullName
xtype: 'box',
autoEl: {tag: 'img', src:'img/silk/user.png'}

My AJAX request brings back "Firstname Secondname" as the reponse.



11 Sep 2009, 5:29 AM
You have to study up on asynchronous requests!

Ext.Ajax.request() doesn't stop until it gets a server response. Javascript will simply continue with the next line of code.

You either have to create the entire toolbar inside the success method or you have to update the text of the tbtext component in the success method.