load() trong jQuery ajax

load() trong jQuery ajax

load() trong jQuery ajax

Learn more »


Định nghĩa load() trong jQuery

Phương thức load(url,data,callback) trong jQuery tải dữ liệu từ server và đặt HTML đã trả về vào trong phần tử được so khớp.

Cú pháp load() trong jQuery

Sau đây là cú pháp cho load(url,data,callback) trong jQuery:

[selector].load( url, [data], [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 load(url,data,callback) trong jQuery:

  • url − Một chuỗi chứa URL để request được gởi tới
  • data − tham số tùy ý này biểu diễn một map của dữ liệu được gửi với request.
  • callback − tham số tùy ý này biểu diễn một hàm mà được thực thi nếu request thành công.

Ví dụ load() trong jQuery

Giả sử chúng ta có nội dung HTML sau trong result.html file:

<h1>THIS IS RESULT...</h1>

Sau đây là ví dụ đơn giản minh họa cách sử dụng của phương thức load(url,data,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){                $('#stage').load('../result.html');             });          });       </script>     </head>     <body>        <p>Click on the button to load result.html 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 : 290

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