Ajax call how to force data to download in browser

For some reason this is not forcing a download of binary data that represents a pdf file? What am I doing wrong?

$tracking_number = 1;
$data = $this->OrderHistory->labelRecovery->makeSoapRequest($tracking_number);
$reportFileName = “Jason”;

		$this->layout = 'bare';
		ob_clean();
		header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");
		header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		header("Cache-Control: no-cache");
		header("Cache-Control: public");
		header('Content-Type: application/pdf');			
		//header('Content-Disposition: inline; filename=' . $reportFileName . '.pdf');
		ob_start();

		$myfile = fopen('php://output', 'w');
		fwrite($myfile, $data);
		flush();
		$out = ob_get_clean();
		header("Content-Length: " . strlen($out));
		echo $out;
		fclose($myfile);
		exit;

I can’t tell you for sure what the problem is there, but have you tried using Cakes response to output the file? You can find out more about it here. https://book.cakephp.org/3.0/en/controllers/request-response.html#sending-files