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