doujia1163
2016-12-31 12:08
浏览 240
已采纳

在运行PHP脚本时显示加载符号

I have created a Sign Up page on my website, where users enter their details and click a button which then does some word checks, send an email, inserts the information into a MySQL database and finally ends with a die() statement.

The only problem is that this process can take up to 30 seconds depending on the internet speed of the client. This means that the Sign Up page is displayed for a long period of time which would make a less tech-savvy user (and even a very tech-savvy user!) think the page is broken, which would cause them to close down the website and never come back!

So I need a solution and I think the easiest way to keep a User on the site is to display a loading symbol to say that it's working and how long left. Even though there is a URL loading symbol in the browser tab, it is slow moving and not many people do see it at all.

Basically I am asking for a way to display the loading symbols whilst the script runs and then goes away once it reaches the die() statement. I don't mind which language it's written in but would prefer PHP.

Thanks in advance

图片转代码服务由CSDN问答提供 功能建议

我在我的网站上创建了一个注册页面,用户可以在其中输入详细信息并单击按钮然后执行某些操作 单词检查,发送电子邮件,将信息插入MySQL数据库,最后以 die()语句结束。

唯一的问题是这个过程可以 最多需要30秒,具体取决于客户端的互联网速度。 这意味着注册页面会显示很长一段时间,这会让精通技术的用户(甚至是一个非常精通技术的用户!)认为页面被破坏,这会导致他们关闭网站 并且永远不会回来!

所以我需要一个解决方案,我认为在网站上保留用户的最简单方法是显示一个加载符号,表示它正在工作以及剩下多长时间。 即使浏览器选项卡中有一个URL加载符号,它移动缓慢,根本没有人看到它。

基本上我要求一种方法来显示加载符号 当脚本运行时,一旦到达 die()语句就会消失。 我不介意它写的是哪种语言,但更喜欢PHP。

提前致谢

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doudu2515 2016-12-31 12:26
    已采纳

    The most simple method to achieve this would be to use some JavaScript to attach an event listener to the submit event of your form, then display some message / loading icon / something from that event listener method.

    A quick example (but there are many-many other approaches):

    ...
    <form ... onsubmit="showLoadingMessage();" ...>
    ...
    
    <script>
    function showLoadingMessage() {
      var message = document.createElement('div');
      message.innerHTML = 'We are working. Please wait...';
      document.body.appendChild(message);
    }
    </script>
    

    Of course, you can display anything else instead of that simple text message and you can append to or position that message div where you want to.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题