Php 使用ajax请求新页面并在新页面中打开它
我在尝试使用JQuery Ajax从CodeIgniter请求新页面并在新的空白页面中打开它们时遇到问题 以下是当前代码正在运行的示例场景 1.)用户通过复选框选择客户的收据Php 使用ajax请求新页面并在新页面中打开它,php,jquery,codeigniter,Php,Jquery,Codeigniter,我在尝试使用JQuery Ajax从CodeIgniter请求新页面并在新的空白页面中打开它们时遇到问题 以下是当前代码正在运行的示例场景 1.)用户通过复选框选择客户的收据 <input type='checkbox' class='customer_id' value='<?php echo $entry->customer_id;?>'> 3.)CodeIgniter从数据库检索客户数据并生成页面 function getReceipt(){ $co
<input type='checkbox' class='customer_id' value='<?php echo $entry->customer_id;?>'>
3.)CodeIgniter从数据库检索客户数据并生成页面
function getReceipt(){
$counter = 1;
while ($this->input->post('customer_' + $counter)){
$where['customer_id'] = $this->input->post('customer_' + $counter);
$data += $this->getCustomerReciept($where);
}
$this->load->page('finance/receipt', $data);
}
但是现在我需要转换这个代码,让它用一个打印按钮打开一个新的空白页
这样做的目的是因为我想生成一个格式化的收据,并显示在一个带有打印按钮的新空白页中。我知道有几个插件,我可以打印一个div,但这是我的客户端的请求。所以,这不是我的解决方案
任何建议或评论都会很好。提前感谢。我认为最简单的方法是创建一个辅助的
表单
来将数据发布到新页面,而不是使用$。post
因此,以下是代码:
var data;
var counter = 1;
$(.customer_id:checked).each(function(){
data['customer_' + counter] = $(this).val();
});
$('<form action="finance/getReceipt" method="POST" target="_blank" style="display:none">' +
'<input type="hidden" name="data1" value="value-data1" />'
).appendTo("body").submit().remove();
var数据;
var计数器=1;
$(.customer\u id:选中)。每个(函数(){
数据['customer_'+counter]=$(this.val();
});
$('' +
''
).appendTo(“body”).submit().remove();
只需将data1
param更改为所需的参数,或者如果需要,可以添加更多参数。
就这样。神奇之处在于为表单使用\u blank
目标
希望这有帮助。干杯
另一种方法是用
窗口创建一个新窗口。打开并用javascript分配其内容。非常感谢!!!这是一种有趣的方法。我对使用您提到的javascript分配其内容很感兴趣。你能告诉我怎么做吗
var data;
var counter = 1;
$(.customer_id:checked).each(function(){
data['customer_' + counter] = $(this).val();
});
$('<form action="finance/getReceipt" method="POST" target="_blank" style="display:none">' +
'<input type="hidden" name="data1" value="value-data1" />'
).appendTo("body").submit().remove();