NORMAL File:Open.txt
This is a text from an external file.It is added to the web page without reloading.
HTML FILE : index.html
<!DOCTYPE html>
<html>
<head>
<title>Ajax example</title>
<script type="text/javascript">
function loadContent(txt) {
var ajaxobject;
if (XMLHttpRequest) {
ajaxobject = new XMLHttpRequest();
} else {
ajaxobject = new ActiveXObject("Microsoft.XMLHTTP");
}
ajaxobject.open("GET", txt, true);
ajaxobject.onreadystatechange = function() {
if (ajaxobject.readyState == 4 && ajaxobject.status == 200) {
document.getElementById("output").innerHTML = ajaxobject.responseText;
}
};
ajaxobject.send();
}
loadContent("open.txt");
</script>
</head>
<body>
<h1 id="output">here the page contents will be written</h1>
</body>
</html>
Output :
This is a text from an external file.It is added to the web page without reloading.
HTML FILE : index.html
<!DOCTYPE html>
<html>
<head>
<title>Ajax example</title>
<script type="text/javascript">
function loadContent(txt) {
var ajaxobject;
if (XMLHttpRequest) {
ajaxobject = new XMLHttpRequest();
} else {
ajaxobject = new ActiveXObject("Microsoft.XMLHTTP");
}
ajaxobject.open("GET", txt, true);
ajaxobject.onreadystatechange = function() {
if (ajaxobject.readyState == 4 && ajaxobject.status == 200) {
document.getElementById("output").innerHTML = ajaxobject.responseText;
}
};
ajaxobject.send();
}
loadContent("open.txt");
</script>
</head>
<body>
<h1 id="output">here the page contents will be written</h1>
</body>
</html>
Output :
No comments:
Post a Comment