This article mainly introduces PHP ajax asynchronous execution does not wait for the implementation of the results of the processing method, this article directly gives the implementation code, the need for friends can refer to the
Short address generation application, to generate a snapshot of the Web page based on the long address, this generation time is not instantaneous, unpredictable.
So the foreground of the scheme used in general for the first show the generated short address, and then periodically Ajax round to check the page snapshot is generated.
so,php code here does the following:
The code is as follows:
Here the server is using PHANTOMJS to generate a snapshot of the Web page
$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) {}
Ajax script for front desk JS:
The code is as follows:
_WT = Window.setinterval ("Sys.ajax" ('? M=shorturl&c=index&a=check_snap ', ', Callback.checksnap); ", 200);
The callback function Checksnap waits for the check_snap of PHP to detect whether the snapshot file of the Web page has been generated.
After receiving the generated information, clear _WT the timer.
The code is as follows:
Cleartimeout (_WT);
In this way, PHP and the foreground Ajax this to JFYF cooperation is very happy ~