我创建了一个PHP页面来打印项目的发票。我需要在保存发票后自动打印此页面。我用jquery $ .post方法打开print.php页面,
保存发票按钮
$.post("print.php",{
desc: $desc,
}, function(data,success){
alert(success);
});
我在print.php页面中使用了javascript window.onload = function(){window.print();}
。但它不起作用,没有打印。然后我在浏览器中打开print.php页面并按我的意愿打印。我不需要重定向到print.php页面。
我的代码有什么问题。如何打印此页面?
修改
我无需保存或获取此$.post
的结果。我只需要打印带有desc
数据的发票。
答案 0 :(得分:0)
问题:页面没有加载,所以window.onload不起作用。这是因为你发布了ajax。 解决方案:尝试使用表单过帐发票详细信息。
答案 1 :(得分:0)
尝试在public interface ISizable
{
void SetSize(Size size, ISetSizeProvider provider); //Alternatively inject provider in SizableA and SizableB's constructor to get composition.
}
之后链接#include <stdio.h>
int main()
{
int *value;
value = (int *)malloc(20 * sizeof(int));
//float answer;
int x;
int y;
for(x=0; x < 20; x++)
{
scanf("%d" , value + i);
}
for(x=0; x < 20; x++)
{
y = value[x];
printf("\nThe square of %d is: %d" , y , y*y);
printf("\nThe cube of %d is: %d \n" , y , y*y*y);
}
return 0;
}
。
done()
抬起头来!
使用post()
代替$.post( "print.php", { desc: invoiceData })
.done(function( data ) {
alert( "Success: " + data );
});
向请求print.php
提醒结果,因为: done()
,success()
和jqXHR.success()
从jQuery 3.0开始,删除了回调方法。您可以改为使用jqXHR.error()
,jqXHR.complete()
和jqXHR.done()
。
答案 2 :(得分:0)
如果您只想打印ajax的响应,请使用以下代码。
$.post("print.php",{
desc: $desc,
}, function(data,success){
alert(success);
w=window.open(null, 'Print_Page', 'scrollbars=yes');
w.document.write(data); //where data = response of print.php, the invoice
w.document.close();
w.print();
}
);
注意:我假设如果我在浏览器中打开print.php,那么我将以人类可读的方式获取发票,无论是原始文本还是HTML,无论您将看到什么在浏览器中打开print.php,将按原样打印。