I have a front end editor set up using AJAX to edit posts in Wordpress. Everything was going good, my form submits to a php file which successully updates the database and then uses the following function to create a response:
function generate_response($action, $message = '', $details = '' ){
$response = array(
"action" => $action,
"message" => $message,
"details" => $details
);
echo json_encode($response, JSON_FORCE_OBJECT);
}
However, the response does not appear to be encoded properly, When I log my jsonResponse return in JS I'm getting this:
Object {action: "updated", message: "Succes (no changes detected).", details: ""}
Which I'm pretty sure is malforemd JSON because action, message, and details are not double-quoted, right?
I try to parse the response and all I get is null:
response = jQuery.parseJSON(jsonResponse);
console.log(response); //returns null
What am I doing wrong here? Am I correct and the response is not fomratted properly and if so, how would I fix it?