How to use load() Method in JQuery AJAX

In this article, I will explain use of load() Method in JQuery AJAX.
  • 2986

JQuery AJAX load() Method

  • load() method loads data from the server using AJAX request and places the returned HTML into the matched element.
  • load() method is also a jQuery Event method called load.

Syntax

$(selector).load(url,data,function(response,status,xhr))

Parameter

  • url url is required parameter. A string containing the URL to which the request is sent
  • data data contains the data returned from the server.
  • Success(response,status) this is the optional parameter. the function to run if the request completed
    Additional parameters:

    • response - data contains the result data.
    • status - status contains a string containing request status.
    • xhr xhr contains the XMLHttpRequest object

Example

 

The following example show the use of load() method.

 

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function () {

        $("button").click(function () {

            $("div").load('jquery_ajax_demo.txt');

        });

    });

</script>

</head>

<body>

<h2>load() Method Example</h2>

<button>Click on</button>

<div></div>

</body>

</html>

Output

load.jpg

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.