Javascript examples for jQuery Method and Property:getScript
The getScript() method gets and executes a JavaScript using an AJAX HTTP GET request.
$.getScript(url,function(data,status))
Parameter | Require | Description |
---|---|---|
url | Required. | url to send the request to |
function(response,status) | Optional. | function to run if the request succeeds |
Additional parameters:
The following code shows how to get and run a JavaScript using an AJAX request:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $.getScript("demo.js"); });/*from w w w .j ava 2 s . co m*/ }); </script> </head> <body> <button>Use Ajax to get and then run a JavaScript</button> </body> </html>