0

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

Lili Abedinpour
  • 159
  • 1
  • 4
  • 12
  • Try this: http://stackoverflow.com/questions/333664/simple-long-polling-example-code – Evan Larsen Jun 15 '12 at 17:11
  • ive tried once registration is complete, open a page which stores all registration info then from the main one auto-refresh every few seconds but i want to get a live result only when its completed – Lili Abedinpour Jun 15 '12 at 17:11

4 Answers4

1

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). 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)? To do this you could do a setTimeout() ever certain second to see if the registration has been completed. 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. A faster way would be to use cookies to check if the user has finished their registration.

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). It is also relatively faster than polling relational database.

40pro
  • 1,283
  • 2
  • 15
  • 23
0

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
  3. When the message has arrived, return "true". If it hasn't return "false"
  4. Perform your actions on the client side when the client recieves a "true".
Jonas Stensved
  • 14,378
  • 5
  • 51
  • 80
  • yah but all of this needs to be checked every second to see if result is changed, i want the main page to do something when result is true or complete without checking it repeatedly – Lili Abedinpour Jun 15 '12 at 17:14
  • I agree it would be nice but unfortunately the web doesn't work that way (except for some html5 methods). Since there's no connection between the server and the client after the page has been fetched there is no way the server can notify the browser unless the browser itself makes a new connection and "asks" for info. – Jonas Stensved Jun 18 '12 at 07:09
0

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.

Oleg V. Volkov
  • 21,719
  • 4
  • 44
  • 68
0

Use jQuery ajax to send the registration data to server and return some response once the transaction (saving user to database) is completed. 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.

Shyju
  • 214,206
  • 104
  • 411
  • 497