jQuery getScript()Method

jQuery AJAX 方法jQuery AJAX Methods

Example

Use an AJAX request to get and run JavaScript:

$("button").click(function(){ $.getScript("demo_ajax_script.js"); });

Try it Yourself »

Definition and Usage

The getScript() method uses an AJAX HTTP GET request to fetch and execute JavaScript.


Syntax

$(selector).getScript(url,success(response,status))

Parameter Description
url Required. Specifies the URL to which to send the request.
success(response,status) Optional. Specifies the function to run when the request succeeds.
Additional parameters:
  • response- Contains the resulting data from the request
  • status- Contains the status of the request ("success", "notmodified", "error", "timeout", "parsererror")


jQuery AJAX 方法jQuery AJAX Methods

Other Extensions