Home >Web Front-end >JS Tutorial >Ideas and examples of getting html files with js_javascript skills

Ideas and examples of getting html files with js_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:22:141708browse
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
Statement:
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