English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The $.getScript() method uses a GET HTTP request to load a JavaScript file from the server and then execute the file.
$.getScript(URL, callback)
Use AJAX requests to request and execute JavaScript:
$("button").click(function(){ $.getScript("/javascript/myscript.js"); });Test to see‹/›
ThecallbackThe script is triggered once, but it may not necessarily be executed::
$("button").click(function(){ $.getScript("/javascript/myscript.js, function(data, status, xhr){ alert(data); // Data returned alert(status); // Success alert(xhr.status); // 200 }); });Test to see‹/›
Parameters | Description |
---|---|
URL | Specify the URL you want to request |
callback | (Optional) Specify the callback function to be executed after the request is successful Parameters:
|