简体   繁体   English

在运行另一个页面时在提交时刷新 HTML PHP 页面?

[英]Refresh HTML PHP page on submit while running another page?

I've got a page which has a load of invoices on it and I want to be able to delete an invoice and then see that it's been deleted.我有一个页面,上面有很多发票,我希望能够删除发票,然后看到它已被删除。

What I'm using currently is (bastardizing other code as I don't really know HTML / PHP all too well...!)我目前使用的是(混杂其他代码,因为我不太了解 HTML/PHP...!)

  <form name="form1" action="deleteinvoice.php" method="post">
    <input name="invoiceid" type="number" size="20"/>
    <input id="input" 
        type='submit' 
        value='Delete' 
        onclick="form1.action='deleteinvoice.php';target='my-iframe'" 
        class="button save-big" 
        disabled="disabled" >
    <input type="checkbox" 
        name="agree" 
        value="yes" 
        onclick="input.disabled = !this.checked" />Confirm you have the correct invoice number
    </form>

<iframe name="my-iframe" src="deleteinvoice.php" style="display:none"></iframe>      

This is working fine in so far as it's deleting the invoice (so I know the deleteinvoice.php page is working) but what I could really do with it also doing is refreshing the page that I was on so that the deleted invoice disappears and the form is blank again.这在删除发票方面工作正常(所以我知道 deleteinvoice.php 页面正在工作)但我真正可以用它做的是刷新我所在的页面,以便删除的发票消失并且表格又是空白。

Thoughts?想法?

A quick and dirty PHP workaround would be to create yet another PHP page that would delete the invoice and reload the page you're in:一个快速而肮脏的 PHP 解决方法是创建另一个 PHP 页面,该页面将删除发票并重新加载您所在的页面:

<?php
    ob_start();
    require 'deleteinvoice.php';
    ob_end_clean();
    Header("Location: the-page-you-were-looking-before.php");
?>

Then set the form action to然后将表单操作设置为

onclick="form1.action='workaroundpage.php';"

Note: this is not a very clean or secure setup.注意:这不是一个非常干净或安全的设置。 It's just a simple make-do since you say you're not very conversant with PHP.这只是一个简单的凑合,因为您说您不太熟悉 PHP。

What the above code does, is to first load the true "deleteinvoice.php", just as if it was that page.上面代码所做的,是首先加载真正的“deleteinvoice.php”,就好像它是那个页面一样。 So the invoice gets deleted as before.所以发票会像以前一样被删除。 But any output from that page is first buffered by ob_start() and then discarded by ob_end_clean() , making this equivalent (client side) to a blank page.但是该页面的任何输出首先由ob_start()缓冲,然后由ob_end_clean()丢弃,使这等效(客户端)为空白页面。 It then redirects the browser (it can do so, because it's as if no output was created) to the original page, not in the iframe but in the main window.然后它将浏览器(它可以这样做,因为它好像没有创建输出)重定向到原始页面,而不是在 iframe 中,而是在主窗口中。 So you find yourself back at the list page, with the invoice deleted.所以你发现自己回到了列表页面,发票被删除了。

A much more elegant (but proportionately more complex) way of doing this could be eg through a jQuery AJAX call and invoice DOM element destruction.一个更优雅(但比例更复杂)的方法可以是例如通过 jQuery AJAX 调用和发票 DOM 元素销毁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM