How to pass a Javascript Array via JQuery Post so that all its contents are accessible via the PHP $_POST array?

How to send an array via the url in javascript/jQuery?

If you want to pass a JavaScript object/hash (ie. an associative array in PHP) then you would do:

$.post(‘/url/to/page’, {‘key1′: ‘value’, ‘key2′: ‘value’});

If you wanna pass an actual array (ie. an indexed array in PHP) then you can do:

$.post(‘/url/to/page’, {‘someKeyName’: ['value','value']});

If you want to pass a JavaScript array then you can do:

$.post(‘/url/to/page’, {‘someKeyName’: variableName});

About the Author

avatar