PDA

View Full Version : multidimensional array from json php



paweln
30 Jun 2009, 3:53 AM
Hello All,

I have load multidimensional array from php to one multidim array and use this like config data for my site.

I try this, but var 'danezs' is empty out of the success function. I need use danezs globaly!



var danezs = null;

var conn = new Ext.data.Connection();
conn.request({
url: "lib/jsvarconf.php",
method: "POST",
success: createArray
success: function (response) {
danezs = Ext.decode(response.responseText));
}
});

alert(danezs);


Could you give me any sugestion ?

Regards
Pawel

Animal
30 Jun 2009, 3:56 AM
Tell me, when do you think that success function executes, and assigns a value to the danezs variable?

After, or before the alert() call executes?

paweln
30 Jun 2009, 4:08 AM
When put alert(danezs) in the code of success function then display correct value.

Animal
30 Jun 2009, 4:48 AM
So what do you learn from that, and reading the full API docs for Ext.data.Connection.request?

paweln
30 Jun 2009, 5:25 AM
I see the success function call when end of request and is success.
May be I must waiting for that, if yes, tell me how?
I before thinking is work the same like store.
This connection is the first after onReady, I hope is must do before any other.

Animal
30 Jun 2009, 6:28 AM
I give up.

paweln
30 Jun 2009, 11:44 AM
Animal, sorry I'm still not understand.

I try different ways and have the same result.



var danezs = null;

var conn = new Ext.data.Connection();
conn.request({
url: "lib/jsvarconf.php",
method: "POST",
timeout: 30,
scope: this,
callback: function (opt, succ, response) {
danezs = Ext.decode(response.responseText);
alert(danezs.language); // this work ok
}
});

alert(danezs.language); // this NOT work


I think, var danezs in the callback function is not the same danezs defined on top.
Tell me, how to apply global danezs in callback function?

Or may be you have other solution ?

Regards,
Pawel

Joe
30 Jun 2009, 12:05 PM
I see the success function call when end of request and is success.
May be I must waiting for that, if yes, tell me how?


Welcome to the world of no waiting. There is no waiting around for this to end due to how the web works.

This is very different from standard programming and takes some time to get used to. You will hit this ALOT when web programming and you have to change not only how your process works .. but how you think about it.

So in this case .. if you consider once you have made the call .. that is it. Then do what you are trying to "wait for" in the callback function code.

Hope that helps clear up what is happening here and why.

paweln
30 Jun 2009, 12:29 PM
What I see in firebug - response for this function (receive the json stream) is the first of other my code. After this connection I have two another store and after that use this variable.
Ok. I try find other solution for load multidim array.
Any way, thanks for support.

Regards,
Pawel

Joe
30 Jun 2009, 12:53 PM
alert(danezs.language); // this work ok

There in your code .. do your stuff there where it works .. not where it does not work.

Good Luck.