Home Web Front-end JS Tutorial Jquery code to handle multiple ajax requests at one time_jquery

Jquery code to handle multiple ajax requests at one time_jquery

May 16, 2016 pm 06:02 PM
ajax request

Copy code The code is as follows:

$(document).ready(function () {
$ ('#getsetgo').click(function () {
$.when($.ajax("page1.php"), $.ajax("page2.php")).done(function(a1, a2 ){
$('#id1').html(a1[0]);
$('#id2').html(a2[0]);
});
} );
});

After the release of jquery 1.5, a new method jQuery.when(). can handle multiple ajax requests at one time. See jquery api documentation for more details.
Collection by Ancker

Another way jquery handles multiple ajax requests on the same page
Add a parameter
Copy code The code is as follows:

$.post(
"doSysthFile.aspx",
{
type: '1 '
},
function(data, textStatus)
{
},
"json");
$.post(
"doSysthFile.aspx",
{
type: '2'
},
function(data, textStatus)
{
},
"json");

In the doSysthFile.aspx.cs file:
Copy the code The code is as follows:

if (( !string.IsNullOrEmpty(Request["type"])) && (Request["type"] == "1"))
{
//do something
}
if ((! string.IsNullOrEmpty(Request["type"])) && (Request["type"] == "2"))
{
//do something
}

This different ajax request can be processed by the same page, and there is no need to create a new page for each ajax request.
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to extend the timeout of Ajax requests? How to extend the timeout of Ajax requests? Jan 26, 2024 am 10:09 AM

How to extend the expiration time of Ajax requests? When making network requests, we often encounter situations where we need to process large amounts of data or complex calculations, which may cause the request to time out and fail to return data normally. In order to solve this problem, we can ensure that the request can be completed successfully by extending the expiration time of the Ajax request. The following will introduce some methods and specific code examples to extend the expiration time of Ajax requests. When making an Ajax request using the timeout attribute, you can set the timeout attribute to

How long does it take for ajax requests to expire? How long does it take for ajax requests to expire? Nov 20, 2023 am 10:29 AM

AJAX requests have no fixed expiration time: "Asynchronous JavaScript and XML" is a technology for sending asynchronous requests on web pages, which uses JavaScript to send requests to the server and receive responses without refreshing the entire page.

How to use controllers to handle Ajax requests in the Yii framework How to use controllers to handle Ajax requests in the Yii framework Jul 28, 2023 pm 07:37 PM

In the Yii framework, controllers play an important role in processing requests. In addition to handling regular page requests, controllers can also be used to handle Ajax requests. This article will introduce how to handle Ajax requests in the Yii framework and provide code examples. In the Yii framework, processing Ajax requests can be carried out through the following steps: The first step is to create a controller (Controller) class. You can inherit the basic controller class yiiwebCo provided by the Yii framework

How to choose the right Ajax request library for your project How to choose the right Ajax request library for your project Jan 30, 2024 am 08:32 AM

Practical guide: Which Ajax request libraries are suitable for your project? With the continuous development of front-end development, Ajax has become an indispensable part of web development. Choosing an Ajax request library suitable for the project is crucial to improving development efficiency and optimizing user experience. This article will introduce several commonly used Ajax request libraries to help readers choose the tool suitable for their own projects. jQueryAjax There is no denying that jQuery is one of the most popular JavaScript libraries out there. It provides a rich

Essential tools: Understand what are the commonly used Ajax request libraries? Essential tools: Understand what are the commonly used Ajax request libraries? Jan 30, 2024 am 11:00 AM

Development essentials: Explore what are the commonly used Ajax request libraries? In modern front-end development, using Ajax for asynchronous requests has become a standard feature, and choosing an appropriate Ajax request library can allow us to process network requests more efficiently, improving development efficiency and user experience. This article will explore some commonly used Ajax request libraries to help developers choose the tools suitable for their projects. jQueryAjax: As one of the most popular JavaScript libraries, jQuery provides powerful Ajax request functions.

Can I customize the expiration time of Ajax requests? Can I customize the expiration time of Ajax requests? Jan 26, 2024 am 11:13 AM

Can the expiration time of Ajax requests be customized? In web development, we often use Ajax to implement asynchronous requests to dynamically load data in the page. When making Ajax requests, sometimes we need to control the timeout of the request, that is, set a time limit, and process it if no response is received within the specified time. So, can the expiration time of Ajax requests be customized? This article will introduce this problem in detail and provide specific code examples. Using jQuery's Ajax function

What causes an Ajax request to timeout? What causes an Ajax request to timeout? Jan 26, 2024 am 10:53 AM

Under what circumstances will an Ajax request expire? With the development of Web applications, Ajax (Asynchronous JavaScript and XML) technology has become an essential part of Web development. Through Ajax, we can obtain data from the server and dynamically update the content of the web page without refreshing the entire page. However, when using Ajax to send requests, sometimes you encounter request expiration. So, under what circumstances will an Ajax request expire?

How to set the timeout for Ajax requests? How to set the timeout for Ajax requests? Jan 26, 2024 am 09:23 AM

How to set the expiration time of Ajax request? Need specific code examples With the development of Internet applications, Ajax has become an indispensable part of Web development. When sending an Ajax request, sometimes we need to limit the expiration time of the request to prevent the request from being too long, resulting in poor user experience or browser freezes. This article will introduce in detail how to set the expiration time of Ajax requests and give specific code examples. Setting the expiration time of Ajax requests mainly requires XMLHttpRequest

See all articles