Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use callback function to return attributes in Ajavx

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use callback function to return attributes in Ajavx. The article is very detailed and has certain reference value. Interested friends must read it!

Return properties using callback functions in Ajavx

A callback function is a function passed as an argument to another function.

If you have multiple AJAX tasks on your site, you should create a function that executes the XMLHttpRequest object and a callback function for each AJAX task.

The function should contain the URL and the function to call when the response is ready.

examples

loadDoc("url-1", myFunction1);

loadDoc("url-2", myFunction2);

function loadDoc(url, cFunction) {

var xhttp;

xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function() {

if (this.readyState == 4 && this.status == 200) {

cFunction(this);

}

};

xhttp.open("GET", url, true);

xhttp.send();

}

function myFunction1(xhttp) {

// action goes here

}

function myFunction2(xhttp) {

// action goes here

}

Server Response Properties

attribute description

responseText Gets response data in string form

responseXML Gets response data in XML data form

Server Response Method

method describes

getResponseHeader() Returns specific header information from the server

getAllResponseHeaders() Returns all header information from the server

The above is "how to use callback function to return attributes in Ajavx" all the contents of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report