PHP ajax asynchronous execution without waiting for execution results
This article mainly introduces how to handle PHP ajax asynchronous execution without waiting for execution results. This article provides the implementation code directly. For more information, see
When generating an application with a short address, you must generate a web snapshot based on the long address. This generated time is not instantaneous and cannot be estimated.
Therefore, the front-end solution generally displays the generated short address first, and then regularly checks whether the Web snapshot is generated.
So, PHP code is processed as follows:
The Code is as follows:
// The server uses phantomjs to generate Web snapshots.
$ Cd = '/home/emp/phpinstall/phantomjs-1.5.0/bin/phantomjs/home/emp/phpinstall/phantomjs/snap. js "'. $ url. '"/home/emp/public_html_demo/cms /'. $ thumb. '&';
Try {
@ Pclose (popen ($ cd, "r "));
} Catch (Exception $ e ){}
Front-end Js ajax script:
The Code is as follows:
_ Wt = window. setInterval ("sys. ajax ('? M = signed URL & c = index & a = check_snap ', '', callback. checkSnap);", 200 );
The callback function checkSnap waits for PHP's check_snap to check whether the webpage snapshot file has been generated.
After receiving the generated information, the _ wt timer is clear.
The Code is as follows:
ClearTimeout (_ wt );
In this way, PHP and the front-end AJAX work happily with JFYF ~