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 get the contents of site files by Ajax

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

Share

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

This article to share with you is about Ajax how to get site file content, Xiaobian feel quite practical, so share to everyone to learn, I hope you can have some harvest after reading this article, not much to say, follow Xiaobian to see it.

A simple Ajax example: Select a book and get the relevant names in real time via Ajax.

Put four html files under the same file on your web site.

index.html

The code is as follows:

A simple Ajax instance that doesn't involve servers

//declare a variable that references XMLHttpRequest

var xhr = null;

//Select a function to call when writing

function updateCharacters() {

var selectShow = document.getElementById("selShow").value;

if (selectShow == "") {

document.getElementById("divCharacters")[xss_clean] = "";

return ;

}

//instantiate an XMLHttpRequest object

if (window.XMLHttpRequest) {

//Non-IE

xhr = new XMLHttpRequest();

} else {

// IE

xhr = new ActiveXObject("Microsoft.XMLHTTP");

}

xhr.onreadystatechange = callbackHandler;

url = selectShow + ".html";

xhr.open("post", url, true);

xhr.send(null);

}

// this is the function that will repeatedly be called by our

// XMLHttpRequest object during the life cycle of request

function callbackHandler() {

if (xhr.readyState == 4) {

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

}

}

Our first Ajax instance

Choose a book:

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