How to handle ajax cancellation of pending requests_PHP tutorial

WBOY
Release: 2016-07-21 15:12:18
Original
990 people have browsed it

When we switch tabs, if we use ajax technology, we will encounter the following situation: click the tab1 option, and the server sends an Ajax request to obtain the content data of tab1 of this option. If the request is being processed, and during this process you click the tab2 option and send a new request, the server now has two requests pending. The result that appears on the page is that when the data content is displayed, the content data of the tab1 option is displayed first, and then the content of the tab2 option is displayed. In this case, we should cancel the pending request of tab1 and only allow processing of the current (tab2) request to create a new index.html. The code is as follows:

Copy code The code is as follows:









Create another 4.php file with the following code:
Copy the code The code is as follows:

sleep(1);
if(isset($_GET['what']))
{
switch($_GET['what'])
{
case 1: echo '111111111111111';
break;
case 2:
echo '2222222222222222';
break;
default: echo 'No content';
}
}

?>

You also need to create a folder js,

put a jquery-1.4.4.min.js file in it,

does not necessarily have to be version 1.4.4;
create one Folder img,
put a loading.gif waiting image in it. Put index.html + 4.php + js (folder) + img (folder) into the www file, and run it with a browser


http://www.bkjia.com/PHPjc/326729.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326729.htmlTechArticleWhen we switch tabs, if we use ajax technology, we will encounter the following situation: click the tab1 option , the server sends an Ajax request to obtain the content data of tab1 of this option. If...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!