Loads an html page to a specified div implementation using jQuery
- 2021-07-04 17:40:05
- OfStack
1. jQuery Loads 1 html page into the specified div
Load part 1 of a. html into an div of b. html.
For example: Load a. html < div id = "row" > < /div > Everything in this div is loaded into this div in b. html < div id="content" > < /div >
It can be realized with jquery ajax
Assume that a. html and b. html are in the same directory
b.html
<script >
$(document).ready(function() {
bodyContent = $.ajax({
url: "b.html",
global: false,
type: "POST",
data: ({
id: this.getAttribute('row')
}),
dataType: "html",
async: false,
success: function(msg) {
alert(msg);
}
})
});
</script>
2. juqery $. ajax requests another html page to load the specified "1 part" into this page div, with emphasis on loading 1 part of data into this page div
The big idea is as follows:
$.ajax( {
url: url, // Here is the address of the static page
type: "GET", // For static pages get Method, otherwise the server throws a 405 Errors
success: function(data){
var result = $(data).find(" Another 1 A html Specified for the page 1 Part ");
$(" This page div").html(result);
}
});
Or refer to the following code:
$(function(){
$.ajax({
type:"POST",
url:"LoginLoadArticle.ashx",
data: "type="+escape(" Latest announcement ") ,
success:function(msg){
$(".gonggao").html(msg);
},
error:function(XMLHttpRequest, textStatus, thrownError){}
})
})
If you don't understand the parameters, you can refer to them
3. Detailed explanation and application of parameters of $. ajax () method in JQuery