PHP Ajax asynchronous execution does not wait for execution results of the processing method

Source: Internet
Author: User

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 ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.