设置一个 Javascript 变量,以便可以通过 onunload 函数检查它
我有一个页面显示进货零件,以便可以输入序列号。我有一个 JQuery Ajax 函数,可以更新数据库并隐藏输入序列号的行 id。这里没有问题。
我还在卸载时发送了一封电子邮件,同样没有问题。
我想要做的是在我的ajax函数之后将一个变量设置为1,这样我就可以看到库存有修改,然后在onload
函数中我可以看到股票的状态该变量并决定是否发送电子邮件。
我设置的序列号是:
function updateField(what) {
serial = document.getElementById('serialno_' + what).value;
po = document.getElementById('po_' + what).value;
entry = what;
if (serial != "") {
$("#totalitems").load("stock_ajaxserial.php?id=" + entry + "&stock=" + serial + "&po=" + po);
$("#tr_" + what).hide("slow");
};
}
,我的 onunload 很简单:
function SendEmail()
{
$.get("stock_in_email.php?po=<?php echo $row_rs_po['entry']; ?>&id=<?php echo $row_rs_po['Order_id']; ?>");
}
I have a page that shows incoming stock parts so serial numbers can be entered. I have a JQuery Ajax function that updates the database and hides the line id a serial no is input. No problems here.
I also send an email on unload, again no problems.
What I want to do is to is set a variable to 1 after my ajax function so I can see that there has been an amendment to the stock, and then in the onload
function I can see the status of that variable and decide whether or not to send the email.
my set the serial number is :
function updateField(what) {
serial = document.getElementById('serialno_' + what).value;
po = document.getElementById('po_' + what).value;
entry = what;
if (serial != "") {
$("#totalitems").load("stock_ajaxserial.php?id=" + entry + "&stock=" + serial + "&po=" + po);
$("#tr_" + what).hide("slow");
};
}
and my onunload
is simply:
function SendEmail()
{
$.get("stock_in_email.php?po=<?php echo $row_rs_po['entry']; ?>&id=<?php echo $row_rs_po['Order_id']; ?>");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用cookie在
unload
上设置数据,并在稍后的onload
期间读取数据you could use cookies to set data on the
unload
, and read data during theonload
later您可以在代码外部设置一个全局变量并在内部检查它的值。恕我直言,这不是做你需要的事情的最干净的方式,但我希望这是你想要的。
在您的
onunload
函数中:希望它有帮助。
You can set a global var outside your code and check it's value inside. IMHO isn't the cleanest way of doing what you need, but I hope it is what you want.
and At your
onunload
function:Hope it helps.