简体   繁体   English

服务器端进度完成后是否自动刷新?

[英]Auto refresh when server-side progress is complete?

Okay, I'm trying to do this a mission form, once visitor presses begin, it pops up a new tab with a registration form ( not my actual website ) after they register, this second website will send something to let me know this visitor completed his registration, 好的,我正在尝试执行此任务表格,一旦访客按一下,他们注册后会弹出一个带有注册表格的新标签页(不是我的实际网站),第二个网站会发送一些信息让我认识这位访客完成他的注册,

okay but this is not the thing, i want to receive registration result live from the main webpage which the user started the mission from, how to do this without having to refresh specific page several times to check current status, i want to receive it live once registration is completed from the main page 好的,但这不是问题,我想从用户开始执行任务的主页面实时接收注册结果,如何做到这一点而不必多次刷新特定页面以检查当前状态,我想实时接收一旦从主页完成注册

using jquery, javascript or php or just any possibility to do this 使用jquery,javascript或php或执行此操作的任何可能性

In the first page, you could use $.ajax (http://api.jquery.com/jQuery.ajax/) to post the registration informations to the database and later retrieve it on the second page (using $.ajax as well). 在第一页中,您可以使用$ .ajax(http://api.jquery.com/jQuery.ajax/)将注册信息发布到数据库,然后在第二页上检索它(也使用$ .ajax) )。 The question is how is the second page going to know if the user has finish their business on the first page (which is identified by "window.opener" method)? 问题是第二页如何知道用户是否在第一页上完成了业务(由“ window.opener”方法标识)? To do this you could do a setTimeout() ever certain second to see if the registration has been completed. 为此,您可以每隔一秒钟执行一次setTimeout(),以查看注册是否已完成。 If yes, retrieve the information from the database. 如果是,请从数据库中检索信息。

Although using $.ajax may rely too much on the user's internet connection and I personally find it slow. 尽管使用$ .ajax可能会过多地依赖用户的Internet连接,但我个人认为它很慢。 A faster way would be to use cookies to check if the user has finished their registration. 一种更快的方法是使用Cookie来检查用户是否已完成注册。

There's also this relatively new HTML5 method called "local storage", which acts as a client-side database (unlike cookie, it is can support large amt. of data and you can store your whole registration form on it). 还有一个相对较新的HTML5方法,称为“本地存储”,它用作客户端数据库(与cookie不同,它可以支持大量数据,并且您可以在其中存储整个注册表格)。 It is also relatively faster than polling relational database. 它也比轮询关系数据库相对更快。

You could do it like this: 您可以这样做:

  1. Listen for the message from the second website 收听来自第二个网站的消息
  2. Make the mission form ask your service (every second or what suits your need) with ajax 使用ajax使任务表格询问您的服务(每秒或满足您的需求)
  3. When the message has arrived, return "true". 消息到达后,返回“ true”。 If it hasn't return "false" 如果没有返回“ false”
  4. Perform your actions on the client side when the client recieves a "true". 当客户端收到“ true”时,请在客户端执行操作。

You'll still need to poll home to check if work is done, because server can't initiate connection to client. 您仍然需要轮询首页以检查工作是否完成,因为服务器无法启动与客户端的连接。 To prevent page refresh, use AJAX for polling. 为了防止页面刷新,请使用AJAX进行轮询。

Use jQuery ajax to send the registration data to server and return some response once the transaction (saving user to database) is completed. 使用jQuery ajax将注册数据发送到服务器,并在事务(将用户保存到数据库)完成后返回一些响应。 grab it in the call back function and do further things ( show a message/ reload some part of the page etc...) 在回调函数中抓取它并做进一步的事情(显示消息/重新加载页面的某些部分,等等...)

so send your registration data to server page like this 所以像这样将您的注册数据发送到服务器页面

$(function(){

   $("form").submit(e){
    e.preventDefault();
       $.post("yourRegistrationProcess.php",$("form").serialize(),function(data){
          //You have the response from server in data variable.
          // Do whatever you want next with that.          
       });
   });

});

Assuming you send some response back from yourRegistrationProcess.php (echo "saved"; etc..)once you save the user registration data to the tables. 假设您将用户注册数据保存到表后,就从yourRegistrationProcess.php发送回一些响应(回显为“ saved”;等等。)。

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

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