Phương thức jQuery.getScript(url,[callback]) trong jQuery tải và thực thi một JavaScript file bởi sử dụng một HTTP GET request.
jQuery.getScript() trong jQuery trả về đối tượng XMLHttpRequest.
Sau đây là cú pháp cho jQuery.getScript(url,[callback]) trong jQuery:
$.getScript( url, [callback] )
Tham số
Dưới đây miêu tả chi tiết về các tham số được sử dụng trong phương thức jQuery.getScript(url,[callback]) trong jQuery:
url − Một chuỗi chứa URL để request được gởi tới
Giả sử chúng ta có nội dung JavaScript sau trong result.js file:
function CheckJS(){ alert("This is JavaScript"); } Sau đây là ví dụ đơn giản minh họa cách sử dụng của phương thức jQuery.getScript(url,[callback]) trong jQuery:
<html> <head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#driver").click(function(event){ $.getScript('../result.js', function(jd) { // Call custom function defined in script CheckJS(); }); }); }); </script> </head> <body> <p>Click on the button to load result.js file −</p> <div id="stage" style="background-color:cc0;"> STAGE </div> <input type="button" id="driver" value="Load Data" /> </body> </html> Xem thêm tổng hợp jQuery Ajax
Lượt xem : 332
This is excellent news!
Haven't seen the build yet, I'll look now.
Checking the build now