Metoda jQuery getScript()

Metody jQuery AJAX

Przykład

Pobierz i uruchom JavaScript za pomocą żądania AJAX:

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

Definicja i użycie

Metoda getScript() służy do pobierania i wykonywania kodu JavaScript przy użyciu żądania AJAX HTTP GET.


Składnia

$(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")

Metody jQuery AJAX