I have a silly question, how do I get the post value (
$.ajax({
type: "POST",
url: "b.php",
data: function (data) {
data.firstName = $('#firstName').val();
data.lastName = $('#lastName').val();
}
});
I guess it’s not $_POST[‘firstName’] or $_POST[‘data’]…
Thanks for helping
2
Answers
=.=" It's working now.
ajax:
php
Your $_POST object will contain an array with the name ‘data’, as you are passing a JavaScript object.
I would recommend creating a JavaScript object and then using
JSON.stringify()
to pass to PHP. Try something like this:JavaScript/jQuery
Then, in your PHP controller, you would do something like this:
PHP
You can check the structure using
vardump($userData);