jQuery.getScript() trong jQuery

jQuery.getScript() trong jQuery

jQuery.getScript() trong jQuery

Learn more »


Định nghĩa jQuery.getScript() trong jQuery

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.

Cú pháp jQuery.getScript() trong jQuery

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

  • callback: − tham số tùy ý này biểu diễn một hàm để được thực thi bất cứ khi nào dữ liệu được tải thành công.

Ví dụ minh họa jQuery.getScript() trong jQuery

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

Integrations
Users

Share Profile

Anyone at KeenThemes can view
Anyone with link can edit

Give Award

Anyone at KeenThemes can view
Anyone with link can edit

Report User

Let us know why you’re reporing this person
Don't worry, your report is completely anonymous; the person you're
reporting will not be informed that you've submitted it