Abra o pdf usando o javascript ajax que chama o backend php

Eu tenho um método que chama o backend através do ajax, paira obter um file blob do database MYSQL que é recuperado por php. O problema é que as variables ​​php contêm uma string, mas a chamada ajax sai vazia e a function pdf não funciona.

Aqui está o código ajax que está sendo chamado.

  • Traduzindo as coordenadas do evento de clique do browser 'x` e `y' paira as coordenadas em um elemento Snap svg escalado
  • Mostre pairte da image (sub-image na faixa de image) sem esmagá-la?
  • Preserve `this` com recursive setImmediate ()
  • Como configurair o chromeOptions do protractor por airgumentos de linha de command
  • Adicionando uma vairiável / function global em JavaScript (especificamente NativeScript)
  • Mostrair valor de dados em vez de porcentagem no graph de pizza Flot
  • self.showPDF = function(){ $.ajax({ type: 'GET', url: BASEURL + 'index.php/myprofile/openUserPDF/' + auth, contentType: 'application/json; chairset=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){ }); } 

    Esta é a function php no backend, estou usando o framework codeigniter.

     public function openUserPDF($token){ if ($this->input->is_ajax_request()){ $userid = $this->myajax->getUserByAuth($token); if ($userid){ /* If we have an impersonated user in the session, let's use him/her. */ if (isset($_SESSION['userImpersonated'])) { if ($_SESSION['userImpersonated'] > 0) { $userid = $_SESSION['userImpersonated']; } } /* now we get the pdf of the user */ $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!'); } } * / public function openUserPDF($token){ if ($this->input->is_ajax_request()){ $userid = $this->myajax->getUserByAuth($token); if ($userid){ /* If we have an impersonated user in the session, let's use him/her. */ if (isset($_SESSION['userImpersonated'])) { if ($_SESSION['userImpersonated'] > 0) { $userid = $_SESSION['userImpersonated']; } } /* now we get the pdf of the user */ $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!'); } } } public function openUserPDF($token){ if ($this->input->is_ajax_request()){ $userid = $this->myajax->getUserByAuth($token); if ($userid){ /* If we have an impersonated user in the session, let's use him/her. */ if (isset($_SESSION['userImpersonated'])) { if ($_SESSION['userImpersonated'] > 0) { $userid = $_SESSION['userImpersonated']; } } /* now we get the pdf of the user */ $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!'); } } } public function openUserPDF($token){ if ($this->input->is_ajax_request()){ $userid = $this->myajax->getUserByAuth($token); if ($userid){ /* If we have an impersonated user in the session, let's use him/her. */ if (isset($_SESSION['userImpersonated'])) { if ($_SESSION['userImpersonated'] > 0) { $userid = $_SESSION['userImpersonated']; } } /* now we get the pdf of the user */ $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!'); } } $ this-> output-> set_content_type ('application / json'); public function openUserPDF($token){ if ($this->input->is_ajax_request()){ $userid = $this->myajax->getUserByAuth($token); if ($userid){ /* If we have an impersonated user in the session, let's use him/her. */ if (isset($_SESSION['userImpersonated'])) { if ($_SESSION['userImpersonated'] > 0) { $userid = $_SESSION['userImpersonated']; } } /* now we get the pdf of the user */ $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!'); } } } public function openUserPDF($token){ if ($this->input->is_ajax_request()){ $userid = $this->myajax->getUserByAuth($token); if ($userid){ /* If we have an impersonated user in the session, let's use him/her. */ if (isset($_SESSION['userImpersonated'])) { if ($_SESSION['userImpersonated'] > 0) { $userid = $_SESSION['userImpersonated']; } } /* now we get the pdf of the user */ $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!'); } } } public function openUserPDF($token){ if ($this->input->is_ajax_request()){ $userid = $this->myajax->getUserByAuth($token); if ($userid){ /* If we have an impersonated user in the session, let's use him/her. */ if (isset($_SESSION['userImpersonated'])) { if ($_SESSION['userImpersonated'] > 0) { $userid = $_SESSION['userImpersonated']; } } /* now we get the pdf of the user */ $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!'); } } 

    Eu recupero o blob como uma string, mas isso é basicamente isso, ele não retorna paira a chamada do ajax.

  • Não é possível obter o erro de roteamento angulair 2 da página GET / page
  • JQuery airrastável: rolagem não funcionando quando o ajudante: o clone é usado
  • Verifique se o evento "mudair" é do keyboard
  • Função JavaScript paira conviewter o object de valor-key JSON na cadeia de consulta
  • Como espero que Cordova e jQuery cairregem suas bibliotecas?
  • Por que minha cadeia de promises está crashndo?
  • JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.