I need to pass a two objects and a string as post parameters to php.
This is how my code is now:
var obj1 = {'a':'b', 'c':'d'};
var obj2 = {'e':'f', 'g':'h'};
var url = 'hello';
dataParams = {
object1: obj1,
object2: obj2,
url: url
}
$.ajax({
url: '/sample.php',
dataType: 'json',
method: 'POST',
data: dataParams
});
In sample.php
echo $_POST['url'] gives hello
echo $_POST['object1'] or json_decode($_POST['object1']) gives null.
echo $_POST['object2'] or json_decode($_POST['object2']) gives null.
What is wrong with the code?
var_dump($_POST)in your php sacript to see what json sends you?