I am stuck by creating my first universal code for ajax responses. I simply do not get an output here, neither in php nor in the ajax response. This must have something to be in the post data.
This is my ajax request:
var info = {};
//get id info
info["ses-id"] = $("#theme").attr("scene");
//get template info
info["ses-template"] = $("#theme").attr("template");
$.ajax({
dataType: "json",
contentType: "application/json; charset=UTF-8",
data: JSON.stringify(info),
type: "POST",
url: "query.php"
}).done(function(data, textStatus, jqXHR) {
alert (data);
//window.location = "?szenen";
console.log("Data sent.");
}).fail(function(jqXHR, textStatus, errorThrown) {
console.log("There was an error." + errorThrown);
});
This is my query.php so far:
<?php
$return = $_POST;
$return["json"] = json_encode($return);
print(json_encode($return));
The output is an object where only the json entry is filled with [].
The stringified variable looks good, it's a string like this:
{"ses-id":"1","ses-template":"2"}
Thanks for any advice!
json_decode?An alternative construct to the success callback option, the .done() method replaces the deprecated jqXHR.success() method