galvin Posted July 24, 2012 Share Posted July 24, 2012 On one page, I have a javascript array that gets created while a user is interacting with some JQuery and the page has a submit form. When done interacting with the JQuery, the user submits the form. And I want to post the data in the javascript array to another page with a PHP script, for processing via PHP. What is the best way to do this? I googled it and I am seeing A LOT of differing opinions (JSON, serialize/unserialize, etc. etc) and I am not sure who to believe Any insight would be appreciated. Thanks! Link to comment https://forums.phpfreaks.com/topic/266147-converting-javascript-array-data-to-php-using-post/ Share on other sites More sharing options...
scootstah Posted July 24, 2012 Share Posted July 24, 2012 Use JSON in the jQuery AJAX methods with "post" as the type. Then the $_POST array will be made up from the JSON keys. var name = $('input[name="name"]').val(), email = $('input[name="email"]').val(), address = $('input[name="address"]').val(); $.ajax({ url: example.com, data: { name: name, email : email, address : address }, type: "post" }); $_POST will look like: $_POST = Array ( 'name' => 'bob', 'email' => '[email protected]', 'address' => '123 someplace' ) Link to comment https://forums.phpfreaks.com/topic/266147-converting-javascript-array-data-to-php-using-post/#findComment-1363894 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.