Copy codeThe Code is as follows:
Function readHTML (){
$. Ajax ({
Async: false,
Url: "aa.html",
Success: function (result ){
Alert (result );
}
});
}
Async: false. This is used for synchronization with other JavaScript codes. If it is set to true or not specified, other codes of the same level will be run first, that is, the result here is empty, only after other code is executed will the result have a value. This is generally not required.
The expression may not be very clear, a test is clear, this is a detailed example of this attribute: http://www.cnblogs.com/wlmemail/archive/2010/06/22/1762765.html
Note: This is the jQuery
If Javascript is used, the following code is used:
Copy codeThe Code is as follows:
Var xmlhttp;
If (window. XMLHttpRequest) {// compatible with IE7 +, Firefox, Chrome, Opera, Safari
Xmlhttp = new XMLHttpRequest ();
}
Else {// compatible with IE6 and 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 position of your output. This is a div defined on the page.
This is the source of my problem: http://stackoverflow.com/questions/8197709/javascript-read-html-from-url-into-string
Reference: http://www.w3schools.com/ajax/tryit.asp? Filename = tryajax_first