简体   繁体   English

用按钮刷新php页面

[英]refreshing php page with button

i have simple coding problem. 我有简单的编码问题。 i have created a page with textbox and share button. 我创建了一个包含文本框和共享按钮的页面。 the page also contains one Points up button. 该页面还包含一个积分按钮。

i had a problem with that points up button that when the user click on that button and refresh the page ... a window ask for resend of information 我点击按钮时出现问题,当用户点击该按钮并刷新页面时 ......窗口要求重新发送信息

for that i have used following code which works fine. 因为我使用下面的代码工作正常。

`header('Location: samepageurl.php'); `header('Location:samepageurl.php');

exit;` 退出;`

but the problem with above code is when user scroll down page and click the button. 但上面代码的问题是当用户向下滚动页面并单击按钮时。 the page automatically scrolls up. 页面自动向上滚动。 and user have to manually scroll it down. 并且用户必须手动向下滚动它。

what i want is the page should refresh but it should be on the same location where it was. 我想要的是页面应该刷新但它应该在它所在的同一位置。

if the problem is still unclear please refer the following images 如果问题仍不清楚请参考以下图片 在此输入图像描述

点击按钮后

You can set a fragment identifier. 您可以设置片段标识符。

eg: 例如:

<a name="points_up"></a> <!-- this needs to be near that button, the page will scroll exactly where the element is -->

and redirect him to: 并将他重定向到:

header('Location: samepageurl.php#points_up');
die;

Mihai answer is correct, but as you said that fragment identifier is not working because each user has points up button, you can pass user id as a fragment identifier and make a hidden( display : none; ) <a> tag and pass the user id in front of each user... Mihai的回答是正确的,但正如你所说的那样,片段标识符不起作用,因为每个用户都有点向上按钮,你可以将user id作为片段标识符传递并创建一个隐藏的( display : none;<a>标签并传递给用户id在每个用户面前......

Like this: 像这样:

You can set a prefix before a user id too (optional) 您也可以在用户ID之前设置前缀(可选)

<a name="pu12345" style="display: none;"></a>

<?php
   header('Location: whatever.php#pu12345');
   exit;
?>

You can send the request via ajax instead relying on the normal form submission. 您可以通过ajax发送请求,而不是依赖于正常的表单提交。 That will not affect the scrolling of the current page. 这不会影响当前页面的滚动。

Add this line at the bottom of your page before the the <\\body> tag 在<\\ body>标记之前的页面底部添加此行

<button id="PageRefresh">Refresh a Page in jQuery</button>
<script type="text/javascript">
         $('#PageRefresh').click(function() {
         location.reload();
         });
</script>

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

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