- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
jQuery load() with Examples
The load() method in jQuery is used to load data from a server and puts the returned data into the selected element
Syntax
The syntax is as follows −
$(selector).load(url,data,function(response,status,xhr))
Above, URL is the URL to be loaded. The data parameter is the data to send to the server, whereas the callback function runs when the load() completes.
Example
Let us now see an example to implement the jQuery load() method −
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("div").load("new.txt"); }); }); </script> </head> <body> <div> <p>Demo text...</p> </div> <button>Load Content from server</button> </body> </html>
Output
This will produce the following output −
Click the above button to load content from “new.txt” −
The content visible above is the new.txt file.
Advertisements