简体   繁体   English

PHP提交后重新加载页面数据

[英]Reloading Page Data after PHP Submit

ok folks, 好的伙计们,

I have created a PHP page that is querying a database, and through a whileloop, displays the contents of that database table with a REMOVE and PUSH button. 我创建了一个查询数据库的PHP页面,通过while循环,使用REMOVE和PUSH按钮显示该数据库表的内容。 The REMOVE button removes it from the database entirely, and the PUSH button pushes that entry into another database and sets a variable that the entry has been pushed. REMOVE按钮将其从数据库中完全删除,并且PUSH按钮将该条目推送到另一个数据库并设置一个已推送条目的变量。

What I'm running into is that I can't quite get the page to refresh, in turn running an new query of the first database and displaying only those entries that have not been removed or pushed. 我遇到的是我无法完全刷新页面,反过来运行第一个数据库的新查询并仅显示那些尚未删除或推送的条目。

I can only get the query to run correctly if I manually refresh the page, whether it be F5 or control+r (command+r). 如果我手动刷新页面,无论是F5还是控制+ r(命令+ r),我都只能使查询正确运行。

What is the proper way to refresh the page so that the query will run again on page load? 刷新页面的正确方法是什么,以便在页面加载时再次运行查询?

If you want to reload the page using Javascript, try this: 如果您想使用Javascript重新加载页面,请尝试以下操作:

window.location.reload(true);

You can also see this answer: How to reload a page using JavaScript? 您还可以看到以下答案: 如何使用JavaScript重新加载页面?

there are two ways 有两种方法

If putting extra load on db is not a problem, use jquery methods likes $.get() 如果在db上添加额外的负载不是问题,请使用jquery方法,如$ .get()

$.get('url',{},function(data){
//load results in appropriate div;
});

If you don't want to put any extra load on database just hide the row when it is removed or pushed. 如果您不想在数据库上添加任何额外负载,只需在删除或推送行时隐藏该行。

$('.remove').click(function{
    $(this).css('display','none');
});

similarly make it for pushed 同样也是为了推动它

Do you have some extreme caching setup on your web hosting solution? 您的网络托管解决方案是否有一些极端的缓存设置?

If maintaining nice-looking URLs on this page is a non-issue you could always set a timestamp in PHP and append it to the string. 如果在此页面上保留漂亮的URL是一个非问题,您可以始终在PHP中设置时间戳并将其附加到字符串。

I'm not big on PHP but a javascript example would look something like this. 我对PHP不大,但javascript示例看起来像这样。

ts = new Date();
urltorefresh += '?timestamp=' + ts.getTime();
location.href = urltorefresh;

This would make sure the page is absolutely not in the browser cache since this specific URL have never been requested before. 这将确保页面绝对不在浏览器缓存中,因为之前从未请求过此特定URL。

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

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