I have a PHP function that is supposed to return a JSON object to an AJAX call, but instead it is returning a string. Here is the PHP that I am calling from an AJAX call.
<?php
echo json_encode(array("error", 0, "Success!"));
?>
Here is the AJAX call.
$.ajax({
type: "POST",
url: "../api/login.php",
data: { id: username, password: password },
success: function(response) {
alert( "Data Saved: " + response );
$("#login_username").val("");
$("#login_password").val("");
}
});
When this function returns, I try to access response in the console, and this is what happens
response
> "["error",0,"Success!"]"
response[0]
> "["