Last Updated:
jQuery getScript() Method loads a JavaScript file from the server using a GET HTTP request, then execute it.
Note: Javascript file used in this example is alert-me.js.
Value | Type | Explanation |
---|---|---|
url | Required | Specifies the URL to which the request to be sent. |
success | Optional | Specifies a callback function that is executed if the request succeeds. |
Device | ![]() | ![]() | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Browser | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
getScript() | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
When requesting a large script file, you need to ensure whether the file is loaded completely before calling any function in it. Thus callback is necessary.