Jquery Getscript Example - Jquery

How to get and run a js file using an AJAX request?

Snippet Code

Rate this page :
  [ 0 votes]

This simple jquery code is used to load and execute the javascript file using an ajax http get request. Here getScript() method is used to get and execute a javascript. Sample jquery getscript code is given below.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> $(document).ready(function(){ $("#btn").click(function(){ $.getScript("demo_script.js"); }); }); </script> <input type='button' id='btn' value='Request_here'> demo_script.js: alert("This is demo script");


Ask Questions

Ask Question