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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.