PHP Ajax asynchronous execution does not await the execution of the results of processing methods, Ajax processing methods
In a short address generation application, to generate a Web page snapshot based on a long address, this generation time is non-instantaneous and not predictable.
So the front-end use of the scheme is generally to show the generated short address, and then periodically Ajax polling page snapshot is generated.
The so,php code here is handled as follows:
Copy the Code code as follows:
This way the server uses PHANTOMJS to generate a snapshot of the 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) {}
Front-desk JS Ajax script:
Copy the Code code as follows:
_WT = Window.setinterval ("Sys.ajax ('? M=shorturl&c=index&a=check_snap ', '", Callback.checksnap); ", 200);
The callback function Checksnap waits for PHP check_snap to detect if a webpage snapshot file is generated.
After receiving the generated information, clearly _WT the timer.
Copy the Code code as follows:
Cleartimeout (_WT);
In this way, PHP and the front desk Ajax this pair of JFYF cooperation is very happy ~
http://www.bkjia.com/PHPjc/1008022.html www.bkjia.com true http://www.bkjia.com/PHPjc/1008022.html techarticle PHP Ajax asynchronous execution does not wait for the execution of the results of processing methods, Ajax processing method short address generation application, to generate a Web page snapshot based on the long address, this generation time is not instantaneous, not pre ...