Phương thức jQuery getScript ()

❮ Phương thức jQuery AJAX

Thí dụ

Nhận và chạy JavaScript bằng yêu cầu AJAX:

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

Định nghĩa và Cách sử dụng

Phương thức getScript () được sử dụng để lấy và thực thi JavaScript bằng cách sử dụng yêu cầu AJAX HTTP GET.


Cú pháp

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

Parameter Description
url Required. Specifies the url to send the request to
success(response,status) Optional. Specifies the function to run if the request succeeds
Additional parameters:
  • response - contains the result data from the request
  • status - contains the status of the request ("success", "notmodified", "error", "timeout", or "parsererror")

❮ Phương thức jQuery AJAX