i need to pass this:
"me","you","us"
into a variable but i only ever get the last value when i read back teh variable.
im using xmlhttprequest to get teh info and i have a php file which echos out the above info. i need to get the whole lot as a string so i can pass it back into the javascript staight into an array
how can i do this?
malenski
12-21-2005, 10:54 AM
If the string is the only thing being returned by xmlhttprequest then I'd seperate them by a newline instead of quotes and commas. Then when you get the string back you can break it on newlines using javascript and process them into an array. I don't think xmlhttprequest can return directly to the array in javascript.
how would i break it on newlines using javascript to put them into an array?
malenski
12-21-2005, 12:21 PM
var mystring = "The return string from xmlhttprequest";
var myarray = mystring.split("\n");
ive tried putting the values indei [ ] and also using { }
basically at the moment im using:
var imageArray=new Function("return "+xmlhttp.responseText)();
in the php file i have the code being echod out like this:
[{imgs:"blah.jpg,blah2.jpg,3.jpg"}]
and im now getting a full string but i cant get it so i can use each bit as array element. ive tried using split(",") but that doesnt seem to work either
Korvan
12-21-2005, 04:42 PM
so you want it to echo to the page as
var imagearray = new array("blah.jpg","blah2.jpg","3.jpg");
?
right?
so to do that you would write in php
<?php
$list = "\"blah.jpg\",\"blah2.jpg\",\"3.jpg\"";
?>
<!-- your page in here... etc-->
var imagearray = new array(<?php echo($list);?>)
would produce the result
var imagearray = new array("blah.jpg","blah2.jpg","3.jpg")
thanks for the help in the end i did it by ehcing out as above but then using javascript to get it and the used split to grab each section where there was a , to make the array. works fine :)