Home >>jQuery Tutorial >jQuery $.getScript() Method
jQuery $.getScript() method in jQuery is used to get and execute a JavaScript by using an AJAX HTTP GET request.
Syntax:
$(selector).getScript(url,success(response,status))
Parameter | Description |
---|---|
url | It is s Required parameter and is used to specifies the url to send the request to |
success(response,status) | It is an Optional parameter and is used to specifies the function to run if the request succeeds Additional parameters:
|
Here is an Example of jQuery getScript() Method:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$.getScript("demo_ajax_script.js");
});
});
</script>
</head>
<body>
<button class="btn1">Click me to Use Ajax </button>
</body>
</html>