jQuery.getScript( url [, success ] )Returns: jqXHR
Description: Load a JavaScript file from the server using a GET HTTP request, then execute it.
-
version added: 1.0jQuery.getScript( url [, success ] )
-
urlType: StringA string containing the URL to which the request is sent.
-
successA callback function that is executed if the request succeeds.
-
1
2
3
4
5
|
|
Success Callback
1
2
3
4
5
6
|
|
Handling Errors
.fail()
to account for errors:
1
2
3
4
5
6
7
|
|
ajaxError
callback event had to be used in order to handle $.getScript()
errors:
1
2
3
4
5
|
|
Content-Type
were still executed.
Caching Responses
$.getScript()
sets the cache setting to false
. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested. You can override this feature by setting the cache property globally using $.ajaxSetup()
:
1
2
3
|
|
$.ajax()
method.
Examples:
Example 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
|
Example 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
|