设置一个 Javascript 变量,以便可以通过 onunload 函数检查它

发布于 2024-12-17 08:19:34 字数 808 浏览 3 评论 0原文

我有一个页面显示进货零件,以便可以输入序列号。我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何时共饮酒 2024-12-24 08:19:34

您可以使用cookie在unload上设置数据,并在稍后的onload期间读取数据

you could use cookies to set data on the unload, and read data during the onload later

很酷又爱笑 2024-12-24 08:19:34

您可以在代码外部设置一个全局变量并在内部检查它的值。恕我直言,这不是做你需要的事情的最干净的方式,但我希望这是你想要的。

var ajaxReady = 0;
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, function() {
            ajaxReady = 1;
        });
        $("#tr_" + what).hide("slow");
    };
}

在您的 onunload 函数中:

  function SendEmail()
  {
      if (ajaxReady) // ajax must be done to send e-mail
          $.get("stock_in_email.php?po=<?php echo $row_rs_po['entry']; ?>&id=<?php echo $row_rs_po['Order_id']; ?>");
  } 

希望它有帮助。

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.

var ajaxReady = 0;
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, function() {
            ajaxReady = 1;
        });
        $("#tr_" + what).hide("slow");
    };
}

and At your onunload function:

  function SendEmail()
  {
      if (ajaxReady) // ajax must be done to send e-mail
          $.get("stock_in_email.php?po=<?php echo $row_rs_po['entry']; ?>&id=<?php echo $row_rs_po['Order_id']; ?>");
  } 

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文