Get the App
SLTechnology News&Howtos  ›  Development  › 

How to apply AJAX Asynchronous callback

Shulou Source: shulou.com Published: 2022-06-01 04:46:47 10月06日 Update

This article is a detailed introduction to "how to apply AJAX asynchronous callback". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "how to apply AJAX asynchronous callback" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of Xiaobian.

Asynchronous AJAX

In addition to setTimeout functions, asynchronous callbacks are widely used in AJAX programming.

XMLHttpRequest is often used to request XML or JSON data from a remote server. A standard XMLHttpRequest object often contains multiple callbacks:

examples

var xhr = new XMLHttpRequest();

xhr.onload = function () {

//output received text data

document.getElementById("demo")[xss_clean]=xhr.responseText;

}

xhr.onerror = function () {

document.getElementById("demo")[xss_clean]="Request Error";

}

//Send asynchronous GET requests

xhr.open("GET", "https://www.runoob.com/try/ajax/ajax_info.txt", true);

xhr.send();

The onload and onerror properties of XMLHttpRequest are functions that are called when its request succeeds and when its request fails, respectively. If you use the full jQuery library, you can also use asynchronous AJAX more elegantly:

examples

$.get("https://www.runoob.com/try/ajax/demo_test.php",function(data,status){

alert("data: " + data + "\nstatus: " + status);

});

Read here, this article "AJAX asynchronous callback how to apply" article has been introduced, want to master the knowledge points of this article also need to practice to understand, if you want to know more related content of the article, welcome to pay attention to the industry information channel.

Tags: Applications data articles content functions instances propriety elegance success multiple objects properties ideas text new knowledge more servers standards steps status Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Microsoft NVidia Redmi MariaDB