Jump to content

2 Responses in the same Response?


ryanyoungsma

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.