我有一个javascript代码打印过程。我想要的是,当我点击打印按钮,它将继续打印页面,并在同一时间,它会更新我的表在mysql。我是这样做的…但它只执行打印过程。不是两个. .大家有什么建议吗?
帮助. .(
下面是javascript代码: <script type="text/javascript">
function printpage()
{
document.getElementById('buttonpurchse').style.visibility='hidden';
window.location.reload();
window.print();
$result = mysql_query("UPDATE maklumatimport SET tarikhExpiredEksport = '$date2' WHERE noRujukan = '$noRujukan'");
$row = mysql_fetch_array($result);
}
</script>
这是表单中的按钮。
<button id="buttonpurchse" type="button" title="Print Purchse Request" onClick="printpage()" style="visibility: visible"><img src="img/print.png" height="60" width="100" ></button>
你不能在javascript函数中使用mysql查询,你可以使用ajax来做到这一点,例如
function some(a, b) {
$.ajax({
type: "POST",
url: "someFile.php",
data: {
"a" : a,
"b" : b
},
success: function (r) {
if (r == 1) {
window.location = "home.php";
} else {
alert("something");
}
}
});
}
在"someFile.php"文件中你可以执行你的查询