I have a wierd thing happening where JSON is not being outputted. Chrome is showing
'Failed to load response data'.
My controller task is simple and other instances are returning JSON but for the life of me I cannot figure this out. The below function returns the failed to load message. But if I uncomment out the var_dump() line. I get the var_dump as expected AND the echoed JSON. How can I output just the JSON.
public function updateDealStatus() {
$response_array = array();
$data = $_POST;
if (isset($data["currentDeal"]) && $data["currentDeal"] >= 0) {
$update = array('deal_status' => $data['statusUpdate']);
$this->db->where('deal_id', $data["currentDeal"]);
$this->db->update('deals', $update);
if ($this->db->trans_status() === TRUE) {
$response_array = array('status' => 'success', 'message' => 'Data changed');
} else {
$response_array = array('status' => 'success', 'failed' => 'No data changed');
}
}
header('Content-Type:application/json');
//var_dump(json_encode($response_array));
echo json_encode(array($response_array));
return;
}
Ajax Call:
$.ajax({
type: "POST",
dataType: "json",
url: url,
cache : false,
data: data, // serializes the form's elements.
success: function (res) {
$('#quickTimeModal').modal('toggle');
}
});
More: Adding specifics to the Ajax Call:
contentType: "application/json; charset=utf-8",
dataType: "json",
results with var_dump are:
And 'Failed to load response data'. without the var_dump.