I use JQuery.ajax to send a JavaScript object to a PHP script per POST. JQuery sends it in a way that makes it easily accessable from PHP:
JavaScript:
var request = $.ajax({
url: server,
dataType: 'text',
timeout: timeout,
type: 'POST',
data: {key:"value"}
});
PHP:
$_POST["key"]
When I send a simple string with $.ajax instead of a JS object, how can I access it in PHP? E.g. when simply sending "data", count($_POST) returns 0.
var request = $.ajax({
url: server,
dataType: 'text',
timeout: timeout,
type: 'POST',
contentType: "text/plain",
data: "data"
});
Do I have to use file_get_contents('php://input') or is there another way?