jQuery getScript() Method

jQuery getScript() method used to loads JavaScript data from the server using a HTTP GET request.


Here is a syntax for the getScript() method

$.getScript( url, function(response, textStatus) );
Parameter Type Description
URL String Required. Specifies the URL to send the request to.
success(response, textStatus) Function Optional. A callback function to be run when the request succeeds.
Additional parameters
  • response - contains the result data from the request
  • textStatus - contains the status of the request


function nameAlert(){
   alert("My name is Paul.");

Here, in this example getScript() method call when click on button.

<!DOCTYPE html>
  <title>jQuery get() method</title>
  <script src="jquery-latest.min.js"></script>
  <div id="msg">This text replace with new contains</div>
  <br />
  <button>Click here to call getScript() method</button>

Run it...   »