This article mainly introduces JavaScript based on Ajax to dynamically display file content on the web page without refreshing. It can realize the function of real-time display of txt file content on the server. It is a basic application of Ajax and has certain reference value. Friends who need it can Refer to the following
The example of this article describes the method of using JavaScript to dynamically display file content on a web page without refreshing based on Ajax. Share it with everyone for your reference. The details are as follows:
The following JS code is the most basic JS ajax implementation, which can dynamically display the contents of the ajax_info.txt file on the server
<!DOCTYPE html> <html> <head> <title>sharejs.com</title> <script> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myp").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","ajax_info.txt",true); xmlhttp.send(); } </script> </head> <body> <p id="myp"><h2>Let AJAX change this text</h2></p> <button type="button" onclick="loadXMLDoc()">Change Content</button> </body> </html>
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Solution to 403 error when using jquery ajax post data in django
Detailed explanation of ajax jtemplate implementation Dynamic paging
A simple implementation of Ajax showing progress during the request
The above is the detailed content of JavaScript is based on Ajax to dynamically display file content on the web page without refreshing. For more information, please follow other related articles on the PHP Chinese website!