Login Register

How to parse array returned from xhrGet call

Greetings...

Can anybody point me in the right direction as to how to parse/handle an array returned from xhrGet call.

When calling dojo.xhrGet(kw) the response is a string. But if its an array how does one read it?

I have looked into JSON but there is no specific example on what to do when you receive a response which is an array (from the server). Do I need to convert the PHP array to JSON ? And if so how?

Thanks in advance.

Troy Fandango

xhr array

Just to update, I resolved this by using the "json_encode" in the server-side code to return the response as an JSON array to be read by the javascript.

or handleAs:"json" if your

or handleAs:"json"

if your response is like:

["foo","bar","baz"]

your xhr would look like:

dojo.xhrGet({ url:"foo", handleAs:"json", load:function(data){ dojo.forEach(data, ... ); } });

data would then be an array.