简体   繁体   English

用ajax打开动态php页面

[英]opening dynamic php page with ajax

I have a php script that create user specific pdf files. 我有一个PHP脚本,可以创建用户特定的pdf文件。 (mpdf) (MPDF)

To download the file without losing the current page i used ajax. 为了下载文件而不丢失当前页面,我使用了ajax。

var jsonString = JSON.stringify(multydimarray);
$.ajax({
  type: "POST",
  url: "gen.php",
  data: {data : jsonString}

  success: function(response){
   window.location = "gen.php";
  }
});

But gen.php wasn't received any data from ajax. 但是gen.php没有收到来自ajax的任何数据。 $_POST['data'] wasn't set So, $ _POST ['data']尚未设置,

File was downloaded, Current page stayed untouched, but the file was empty. 文件已下载,当前页面保持不变,但文件为空。

Any suggestion? 有什么建议吗?

specify the ajax request's contentType to application/json; charset=utf-8 将ajax请求的contentType指定为application/json; charset=utf-8 application/json; charset=utf-8

$.ajax({
  type: "POST",
  url: "gen.php",
  data: {data : jsonString}
  contentType: "application/json; charset=utf-8",

  success: function(response){
   window.location = "gen.php";
  }
});

then get the data in PHP like this 然后像这样在PHP中获取数据

$data = json_decode(file_get_contents('php://input'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM