Learn jQuery

jQuery load()

jQuery load() method allows you to loads data from a server and puts returned HTML into the selected element.

Syntax

$(selector).load(URL,data,callback);

Specification

  • URL:specifies url you wish to load.
  • data:object or string that we send to the server along with the request
  • callback:a callback function that is executed when the request completes.

Examples

Load text file.

HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"> </script>
<title>jQuery load() Example </title>
</head>
<body>
<div id="txt"><h2>Get Ajax Content</h2></div>
<button>Load External Content</button>
</body>
</html>
Javascript
$(document).ready(function(){
     $("button").click(function(){
        $("#txt").load("ajax.txt");
    });
});