How to use getScript() Method in JQuery AJAX

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

JQuery AJAX getScript() Method

  • getScript() method loads and executes URL for JavaScript file using an AJAX HTTP GET request.

Syntax

$(selector).getScript(url,success(response,status))

Parameter

  • url: url is required parameter. A string containing the URL to which the request is sent
  • 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.

Example

 

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

 

<!DOCTYPE html>

<html>

<head>

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

<script type="text/javascript">

    $(document).ready(function () {

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

            $.getScript("JScript.js");

        });

    });

</script>

</head>

<body>

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

<button>Click for use JavaScript by AJAX</button>

</body>

</html>

Output

getScript.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

© 2013 dotNetheaven. All rights reserved.