Skip to content
Advertisement

Why array content from php is not inputing to array in js?

I have a little problem, the point is that my array is not getting content.

$staff = array(
"permissions" => false,
"staff" => true,
"group" => 3
);
echo json_encode($staff);
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

header('Content-Type: application/json');

before sending your JSON from server to client. Then the error will be gone.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement