I won't tell you I've searched and tried dozens of syntaxes from the internets. You couldn't tell if I'm lying or not. So...
This is part of my html (the relevant part):
var jsonData = {
address: 'address',
address1: 'address1',
address2: 'address2'
};
var out = JSON.stringify(jsonData);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "joaca2.php",
data: out,
dataType: "html",
success: function (response) {
alert(response);
}
});
And this is the PHP part:
$x = json_decode($_POST, true);
// don't worry: it doesn't get to this line below
printf("<pre>%s</pre>", print_r($x, 1));
I've tried to keep it as simple as possible, maybe some time this year I'll learn about proper JSON.
Here's what I get:
- data sent (clean as a baby's butt)
- html response (xdebug formatted)
- THIS (this... is what gets me mad)
The last image is what I get when the PHP part has this:
var_dump(file_get_contents('php://input'));
Don't start with "Isn't it obvious?!". It is. I know what that error says. I just don't know how to get around it. How am I to grab that post? I've seen $x = json_decode($_POST[]), but that doesn't work either. I've tested the stringified json with JSONlint and it validated. I've tried different types of arrays, objects, array properties, .AJAX, .post(), .get(). I'm out of known options. I've seen all kinds of suggestions and I've pretty much tried them. I know I'm missing something and I'll probably explode or kill my cat when I'll find it.
Thanks, as always
I think I nailed it:
I modified with data: 'kkt=' + out in the code. Now, using this:
$x = json_decode($_POST['kkt'], true);
echo $x['myPostData']['address1'];
...I can get the value. The problem is I don't know how this really works. I know it's a key, though.