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! Quote 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' => 'bob@example.com', 'address' => '123 someplace' ) Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.