Ajax tutorial on how to get the contents of site files
This article introduces the "Ajax get site file content method tutorial" knowledge, in the actual case of the operation process, many people will encounter such a dilemma, then let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
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 copy 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: