I have a little problem, the point is that my array is not getting content.
JavaScript
x
$staff = array(
"permissions" => false,
"staff" => true,
"group" => 3
);
echo json_encode($staff);
JavaScript
let staff = [];
$.ajax({
type: "POST",
url: "../includes/signin.inc.php",
})
.done(function (data) {
staff = JSON.parse(data);
console.log(staff);
})
.fail(function (xhr, status, error) {
alert(status);
});
And i have this error:
Unexpected end of JSON input
Just i want array $staff place into staff in js.
Advertisement
Answer
You should use
JavaScript
header('Content-Type: application/json');
before sending your JSON from server to client. Then the error will be gone.