View Full Version : very simple question of variable scope.

10 Nov 2009, 3:02 AM

Why this code is not working. I mean why variable ses isn't change value.

Sorry for my english, and sorry for that question. Im very beginner.

ses="empty text";

Ext.onReady(function () {

url : 'some_script_with_echo.php' ,
method: 'GET',
success: function ( result, request ) {
ses=result.responseText; //even if ses='some value';

Ext.MessageBox.alert('Outside ses', 'value:'+ses); /display "empty text" not response text

Best Regards


10 Nov 2009, 3:10 AM
It's not scope.

The variable name is in the same lexical scope.

It's time of execution of code that you must think about.

That function that you pass as the success property is called LATER. It is called when, after a few seconds the reply arrives back from the server.

Your Ext.Ajax.request call just runs straight through.

You MUST master this concept in order to work meaningfully with Javascript.