ryanyoungsma Posted February 26, 2011 Share Posted February 26, 2011 Hello All, running into a situation that I have not seen before. I have been seeing in multiple areas of my application that the response received from the server has 2 JSON responses in it. Here is a sample function: private function getCatalogItems(){ $start = ($_REQUEST["start"] == null)? 0 : $_REQUEST["start"]; $count = ($_REQUEST["limit"] == null)? 20 : $_REQUEST["limit"]; $q = "SELECT c.`id`, c.`catalog_number`, c.`long_description`, CONCAT(c.`catalog_number`, ' - ', c.`long_description`) AS `display` FROM catalog c"; if(!empty($_REQUEST['query'])){ $q .= " WHERE c.`catalog_number` LIKE '%".$_POST['query']."%'"; } $q .= " ORDER BY c.`catalog_number` ASC LIMIT ".$start.",".$count; $rs = $this->db->get_results($q); $total = $this->db->num_rows; $buff = '{"total":"'.$total.'","data":'.json_encode($rs).'}'; $this->c->returnJSON($buff); } The "returnJSON" function looks like this. public function returnJSON($json){ $contentType = "application/json; charset=utf-8"; header("Content-Type: {$contentType}"); header("Content-Size: " . strlen($json)); echo $json; } As you can see this simply sets the headers of the response. It has been a real head scratcher. Anyone come across something like this before? Link to comment https://forums.phpfreaks.com/topic/228906-2-responses-in-the-same-response/ Share on other sites More sharing options...
ryanyoungsma Posted February 28, 2011 Author Share Posted February 28, 2011 Does anyone have any thoughts on what could be causing this? Link to comment https://forums.phpfreaks.com/topic/228906-2-responses-in-the-same-response/#findComment-1180958 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.