Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery getScript() method

jQuery getScript() method

jQuery AJAX methods jQuery AJAX methods

Example

Use an AJAX request to retrieve and run JavaScript:

$

(

"

button

"

)

.

click

(

function

(

)

{

$.

getScript

(

"

demo_ajax_script.js

"

)

;

}

)

;

Try it »


Definition and Usage

The getScript() method retrieves and executes JavaScript using an AJAX HTTP GET request.


Syntax

$(

selector

).getScript(

url,success(response,status))

Parameters Description
url Required. Specifies the URL to which the request is sent.
success(response,status) Optional. Specifies the function to run when the request succeeds.
 额外的参数:       

 
  • response - Contains the resulting data from the request
  • status - Contains the status of the request ("success", "notmodified", "error", "timeout", "parsererror")
  • |

    jQuery AJAX methods jQuery AJAX methods