response()->json adding an extra true?
As the title indicates, I'm having an issue with my responses adding additional text at the end of the response. I'm unsure what's causing this, but was hoping for some insight. I'm currently working the the Musixmatch API (fairly standard). Here's some code. Am I missing something obvious?
Controller
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
if($response==null) {
$response = [
'status' => 'failure',
'message' => json_last_error_msg()
];
}
return response()->json($response);
View
$.ajax({
type: "POST",
url: "http://" + document.location.host + "/search",
data: $("#formSearch").serialize(),
success: function(data) {
console.log(data);
var json = JSON.parse(data);
console.log(json);
}
});
event.preventDefault();
The initial console.log shows the unaltered response (with the addition of the word true afterwards) and I get an error on the JSON.parse about non-whitespace (true). I'm able to call the API directly via Postman without issue, but when I use curl+Laravel+JS, it's getting muffed up somewhere. Any ideas/comments/insight is greatly appreciated!
Please or to participate in this conversation.