Home > Web Front-end > JS Tutorial > body text

Ideas and examples of getting html files with js_javascript skills

WBOY
Release: 2016-05-16 17:22:14
Original
1672 people have browsed it
Copy code The code is as follows:

function readHTML(){
$.ajax({
async:false,
url : "aa.html",
success : function(result){
alert(result);
}
});
}

async:false, this is for synchronization with other js. If it is true or not filled in, other codes of the same level will be run first, which means that the result here is empty and only other codes will be executed. The content inside will be run only after the completion, and the result will have a value. This is usually not required.

The expression may not be very clear. You will understand after you test it yourself. This is a detailed introduction to this attribute. Example: http://www.cnblogs.com/wlmemail/archive/2010/06/22/1762765.html

Note: This is using jQuery

If you use js, it is as follows The code of
Copy the code The code is as follows:

var xmlhttp;
if (window. XMLHttpRequest) { // Compatible with IE7, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else { // Compatible with IE6, IE5
xmlhttp = new ActiveXObject("Microsoft .XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("myDiv" ).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "aa.html", true);
xmlhttp.send();

myDiv is the location of your output. This is a div defined on the page

This is the source of my solution to the problem: http://stackoverflow.com/questions/8197709/javascript-read -html-from-url-into-string
Reference: http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template