Jump to content

Recommended Posts

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!

 

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'
)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.