-1

The following code sends (I hope so) a Javascript object to a php file through Jquery's ajax call.

var emails = {};
emails.name = email;
.
.
$('button.gmail').click(function() {                
$.ajax({ url: path,
         data: emails,
     type: 'post',
     success: function(status) { 
        alert(status); 
          }
   });
});

how can I examine this object in PHP and retrieve its keys/values?

3
  • 1
    This will encode the object into a application/x-www-form-urlencoded string, which will be available via $_POST in PHP. Commented Sep 13, 2013 at 17:42
  • 1
    Just do print_r($_POST) in your PHP file, and the alert will show whatever you received in the PHP file, which should be exactly the same as whatever you sent ? Commented Sep 13, 2013 at 17:42
  • See stackoverflow.com/questions/14183837/… Commented Sep 13, 2013 at 17:44

2 Answers 2

0

This will encode the object into a application/x-www-form-urlencoded string, which will be available via $_POST in PHP.

So if your data object is something like:

var data = {
    foo: 'bar',
    baz: 10
};

Then in PHP you will have:

$_POST['foo'] //is "bar"
$_POST['baz'] //is 10
Sign up to request clarification or add additional context in comments.

Comments

0
<?php
  $foo = $_POST['foo']; //this will assign whatever 'foo' was assigned in the javascript POST request

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.