I have a method that calls backend via ajax to get a blob file from the MYSQL database that php retrieves. The problem is that php variables contain a string, but the ajax call comes out empty and the PDF function does not work.
Here is the ajax code that gets called.
self.showPDF = function(){ $.ajax({ type: 'GET', url: BASEURL + 'index.php/myprofile/openUserPDF/' + auth, contentType: 'application/json; charset=utf-8', dataType: 'json', }) .done(function(data) { console.log(data); window.open("data:application/pdf," + escape(data)); }) .fail(function(jqXHR, textStatus, errorThrown) { alert("Could not open pdf" + errorThrown); }) .always(function(data){ }); }
This is a php function in the backend, I am using the frameworkignign framework.
public function openUserPDF($token){ if ($this->input->is_ajax_request()){ $userid = $this->myajax->getUserByAuth($token); if ($userid){ if (isset($_SESSION['userImpersonated'])) { if ($_SESSION['userImpersonated'] > 0) { $userid = $_SESSION['userImpersonated']; } } $this->load->model('user_profile'); $images = $this->user_profile->getUserImageForPDF($userid); $pdfString = $images[0]->image; $this->output->set_content_type('application/json'); return $this->output->set_output(json_encode($pdfString)); } else { return $this->output->set_status_header('401', 'Could not identify the user!'); } } else { return $this->output->set_status_header('400', 'Request not understood as an Ajax request!'); } }
I am extracting blob as a string, but basically it does not go back to the ajax call.
source share