arpit_gadle Posted March 16, 2010 Share Posted March 16, 2010 Dear All, I am a newbie to Javascript and PHP programming. I want to know how one can pass an array of values to a PHP script without using a form. Regards, Arpit U. Gadle Quote Link to comment Share on other sites More sharing options...
Adam Posted March 16, 2010 Share Posted March 16, 2010 Through the URL: example.com/index.php?param1=value1¶m2=value2 Quote Link to comment Share on other sites More sharing options...
arpit_gadle Posted March 16, 2010 Author Share Posted March 16, 2010 thnx for replying... wat i m asking is var array=new array() array[0]="First"; array[1]="Second"; and want to pass this as single(array) request parameter to PHP script. Quote Link to comment Share on other sites More sharing options...
fr34k Posted March 16, 2010 Share Posted March 16, 2010 thnx for replying... wat i m asking is var array=new array() array[0]="First"; array[1]="Second"; and want to pass this as single(array) request parameter to PHP script. The easiest way is still going to be a URL, although you'll need to construct the parameters from your array. Using your example: http://host.com/script.php?array[]=First&array[]=Second In your PHP script, $_GET['array'] would then be a PHP array, containing the values "First," and "Second." Please note that it doesn't need to be named "array." You can name it whatever you like. The important thing is the [] at the end of your URL parameters. Quote Link to comment Share on other sites More sharing options...
ksugihara Posted March 16, 2010 Share Posted March 16, 2010 The thing about GET parameters is they are not (afaik) capable of multi-dimensional values, such as arrays. You could potentially use a cookie, or store in sessions, or a database, but only the later is actually capable of handling an array as an array, and not as just values that can later be constructed into an array. Quote Link to comment Share on other sites More sharing options...
tomfmason Posted March 20, 2010 Share Posted March 20, 2010 The thing about GET parameters is they are not (afaik) capable of multi-dimensional values, such as arrays. um yeah you can eg ?foo[]=test&foo[bar]=baz&foo[bar][baz]=foo Array ( [0] => test [bar] => Array ( [baz] => foo ) ) Also, you could send the javascript object as a json string and then decode it server side rather quickly and without having to loop through the array in javascript to construct the proper url Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.