PDA

View Full Version : Define global Variable



blade226
23 Mar 2012, 1:17 AM
Hello,

i must define a global variabel. I found a normal description in the world wide web, but it didn't work in my case.

Here my code:

Ext.Ajax.request({
url: 'includes/getsession.php',
success: function(resp) {
var xyz = Ext.decode(resp.responseText);
console.log(xyz.recht1);

// Ende Überprüfen der Session Daten
}});

The variable xyz.recht1must be global.

Thanks for help

dedoz
23 Mar 2012, 4:18 AM
xyz.recht1 must be global with the same name ? or you want to have recht1 as gobal ?

to declarate global vars just, assign them and dont use the "var" keyword, var keyword means local var, if theres no "var" keyword then you refereing to the "closest scope" global.
to be sure you have a global var declare it outside any scope. like





// this code is not inside any block
recht1 = null; // declared global var

Ext.Ajax.request({
url: 'includes/getsession.php',
success: function(resp) {
var xyz = Ext.decode(resp.responseText);
console.log(xyz.recht1);
recht1 = xyz.recht1 // assign xyz.recht1 to the recht1 global var
// Ende Überprüfen der Session Daten
}});
hope this helps you