Hi Reader's,
Welcome to FindNerd, today we are going to discuss how to use load() in jquery?
Basically load() method is used for loading data from server and putting return data into selected item,in simple word we can say that load() method is the simplest way to fetch data from the server.
Syntax of load() method
$(selector).load(url,data,function(response,status,xhr))
Let explain one by one
url:- This is specifies the url which you want to load.(Required)
data:-This is optional parameter and specifies data to send to the server with request.
function(response,status,xhr):-This is occur when method is completed.(Optional)
You can see below example:
<!DOCTYPE html>
<html>
<head>
<!--here define css-->
<style type="text/css">
#width {
max-width: 600px;
margin: 0 auto;
color:red;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("#box").load("test.html");//call here load() method and pass the url from where you want load data from server
});
});
</script>
</head>
<body>
<div id="width">
<div id="box"><h2>Let load data from server</h2></div>
<button id ="btn">Load Data</button>
</div>
</body>
</html>
When you will execute above code then after click on Load Data button you can get server data which url you have passed.
0 Comment(s)