如果 isset..php/javascript 则执行操作
插入评论时我正在存储一个会话变量..称为 user_message.. 我想,当 user_message 已存储时,然后在 index.php 上显示消息 index.php 现在是:
<div id="message">
<? echo $_SESSION["user_message"]; ?>
</div>
但是您需要刷新(f5)站点,才能在存储后查看消息..
但我想如果变量 user_message 已存储某些内容,则显示它..
希望您理解。
I am storing a session variable when a comment is inserted.. called user_message..
and i want to, when user_message, have been stored, THEN, show message on index.php
index.php is right now:
<div id="message">
<? echo $_SESSION["user_message"]; ?>
</div>
But you will need to refresh(f5) the site, to see the message AFTER its stored..
But i want to if variable user_message has got stored something, then displays it..
Hope you understand.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定我是否理解您的意图 - 一旦用户发送了新评论,您是否想要刷新用户所在的页面?
如果是这样 - 如果您使用的是普通形式的 post/get,那么您可以使用上面编写的代码 @Seb 将用户请求重定向到您想要的页面,并显示通知。
如果您使用 ajax 发送评论,则可以从 ajax 调用返回响应,通知创建页面需要刷新的 ajax 调用的 javascript 函数,然后将 location.href 变量设置为您设置的 URL想。
但是 - 如果您想刷新所有用户看到评论页面的页面,一旦另一个用户发送了评论,您将需要每隔几秒/分钟重复进行 ajax 调用,以检查服务器中是否有某些内容发生更改,如果是这样,请使用 location.href 变量将用户重定向到不同的位置。
如果您仅依赖评论者计算机上保存的会话变量,则无法执行此操作,因为只有当原始评论者使用您的网站时才能访问该变量。
I'm not sure I understand your intention - do you want to refresh the page the user is on, once he/she has sent a new comment ?
If so - if you're using a normal form post/get, then you can redirect the user request to which ever page you want, and show a notice, using the code @Seb wrote above.
If you're using ajax to send the comment, you can return a response from the ajax call, notifying the javascript function that created the ajax call that the page needs to refresh, and then set the location.href variable to what ever url you want.
However - if you want to refresh the page for all users seeing the comments page, once another user has sent a comment, you will need to have a repeated ajax call every few seconds/minutes, that checks if something has changed in the server, and if so use the location.href variable to redirect the user to a different.
You can't do this if you're relying only on the session variable saved on the computer of the commenter, as it is only accessible when the original commenter is using your site.
如果您希望消息与评论表单显示在同一页面上,我推荐一些 JavaScript。如果您使用 jQuery http://jquery.com/ 那么您可以执行类似的操作。
没有尝试过这个,但应该可以正常工作。
I recommend some Javascript if you want the message to be displayed on the same page as the comments form. If you're using jQuery http://jquery.com/ then you can do something like.
Haven't tried this, but it should work fine.