javascript - 调用一个新的 PHP 页面并传递一个长文本
问题描述
我有一个 PHP 页面(主),想在鼠标单击时调用另一个 PHP 页面(打印页面)。我需要传递一个大文本。
我不想将它作为 url 参数传递,因为它太大了。我想我想将它作为 ajax 传递,但我想打开打印页面,以便可以在浏览器中打印它。
I started with this but the paramater will be too big
$('#MyModal .print').click(function() {
var run = "../js/print.php?ref="+ref;
win = window.open(run, '_blank');
win.focus();
});
我对ajax语句很熟悉,但没有习惯打开新页面。
解决方案
您可以使用带有 a 的不可见表单target="_blank"
并method="post"
提交它,从而在新窗口中发送 POST 请求:
<form name="printForm" style="display: none;" action="../js/print.php" method="post" target="_blank">
<input type="hidden" name="ref">
</form>
$('#MyModal .print').click(function() {
document.forms.printForm.ref.value = ref
document.forms.printForm.submit()
})
然后你得到ref
PHP 中的值$_POST['ref']
推荐阅读
- flutter - 不同设备上的列表放置颤动
- swiftui - SwuftUI 手势位置检测超出视图边框的点击
- javascript - 在页面加载时将多个选项标记为选中
- python - “if”循环与字符串长度测试不匹配
- bash - 用 Windows 编写的 bash 脚本无法正常运行,但如果用 linux 编写则可以
- linux - 计算用户提供的输入数量
- mongodb - MongoDB 聚合根据投影进行不同的排序
- javascript - 如何转换波表以与`OscillatorNode.setPeriodicWave`一起使用?
- python - 重写代码以使用列表推导对初始列表中的值求和
- c# - 如何使用带有 itemclicked 事件的 API 显示信息