jQuery.get() trong jQuery

jQuery.get() trong jQuery

jQuery.get() trong jQuery

Learn more »


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

Phương thức jQuery.get(url,[data],[callback],[type]) tải dữ liệu từ Server bởi sử dụng một GET HTTP request.

Phương thức jQuery.get(url,[data],[callback],[type]) trả về đối tượng XMLHttpRequest.

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

Sau đây là cú pháp cho jQuery.get(url,[data],[callback],[type]) trong jQuery:

$.get( url, [data], [callback], [type] )

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.get(url,[data],[callback],[type]) 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 các cặp key/value mà sẽ được gửi tới server.

  • 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.

  • type: − tham số tùy ý này biểu diễn kiểu dữ liệu để được trả về tới hàm callback: "xml", "html", "script", "json", "jsonp", hoặc "text".

Ví dụ minh họa sử dụng jQuery.get() trong jQuery

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

<?php if( $_REQUEST["name"] ) {    $name = $_REQUEST['name'];    echo "Welcome ". $name; } ?>

Sau đây là ví dụ đơn giản minh họa cách sử dụng của phương thức jQuery.get(url,[data],[callback],[type]) 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){                $.get(                    "../result.php",                   { name: "Zara" },                   function(data) {                      $('#stage').html(data);                   }                );             });          });       </script>     </head>     <body>        <p>Click on the button to load result.html file −</p>        <span id="stage" style="background-color:#cc0;">          STAGE       </span>        <div><input type="button" id="driver" value="Load Data" /></div>     </body>  </html>


Lượt xem : 304

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