Is it possible to put an array of values as an argument to a js function? I want through this function and with AJAX to pass this array to a PHP array inside the PHP script which will then do the rest
Getting arguments with AJAX
Collapse
X
-
Tags: None
-
-
Try something like:
[code=javascript]
var myPostVars = "myArray[0]=AAA&myArray[1]=BBB";
[/code]
then in PHP the $_REQUEST["myArray"] should already be a compiled array.
[code=php]
var_dump($_REQU EST["myArray"]);
[/code]
Not sure it will work, well it did in PHP3, but things have changed since then, but still worth trying. ;)Comment
-
that suggestion shows a 'kind of serializing' a javascript array ... since you cannot use that easyly in both languages ... a very seamless way to handle more complex datatypes is to use JSON ... so that you might use simple eval() on JS-side and json_encode() or json_decode() in php ... that will do the serializing and deserializing for you ...Comment
-
You're right, I'd prefer building an XML in JS and then parse it in PHP, think that would be the right way to do it, or JSON as you mentioned. But the question was about passing an array through an AJAX request.that suggestion shows a 'kind of serializing' a javascript array ... since you cannot use that easyly in both languages ... a very seamless way to handle more complex datatypes is to use JSON ... so that you might use simple eval() on JS-side and json_encode() or json_decode() in php ... that will do the serializing and deserializing for you ...Comment
Comment