Bỏ qua đến nội dung
Bỏ qua điều hướng
Đăng nhập
MT.NET.VN

Viewbh Serialize Trong Jquery Ajax2023 04 11 23 52 50

Tìm kiếm
Thuộc khóa học · baihoc_sub = 18

JQuery căn bản

Bài 1 / 1 trong khóa học.

Xem khóa học
100%
Bài trướcĐây là bài đầu tiên Bài sauĐây là bài cuối cùng
MT LEARNING · LESSON

serialize() trong jQuery Ajax

serialize() trong jQuery Ajax


Định nghĩa serialize() trong jQuery

Phương thức serialize() trong jQuery sắp xếp theo thứ tự một tập hợp các phần tử input vào trong một chuỗi dữ liệu.

Cú pháp serialize() trong jQuery

Sau đây là cú pháp cho serialize() trong jQuery:

$.serialize( )

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 serialize() trong jQuery:

  • NA

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

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

<?php if( $_REQUEST["name"] ) {    $name = $_REQUEST['name'];    echo "Welcome ". $name;    $age = $_REQUEST['age'];    echo "<br />Your age : ". $age;    $sex = $_REQUEST['sex'];    echo "<br />Your gender : ". $sex; } ?>

Sau đây là ví dụ đơn giản minh họa cách sử dụng của phương thức serialize() 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){                 $.post(                    "../serialize.php",                   $("#testform").serialize(),                    function(data) {                      $('#stage1').html(data);                   }                 );                 var str = $("#testform").serialize();                $("#stage2").text(str);             });           });       </script>     </head>     <body>        <p>Click on the button to load result.html file:</p>        <div id="stage1" style="background-color:blue;">          STAGE - 1       </div>       <br />        <div id="stage2" style="background-color:blue;">          STAGE - 2       </div>        <form id="testform">          <table>              <tr>                <td><p>Name:</p></td>                <td><input type="text" name="name" size="40" /></td>             </tr>              <tr>                <td><p>Age:</p></td>                <td><input type="text" name="age" size="40" /></td>             </tr>              <tr>                 <td><p>Sex:</p></td>                 <td> <select name="sex">                   <option value="Male" selected>Male</option>                   <option value="Female" selected>Female</option>                </select></td>              </tr>              <tr>                <td colspan="2">                   <input type="button" id="driver" value="Load Data" />                </td>             </tr>           </table>        </form>     </body>  </html>

Xem thêm tổng hợp jQuery Ajax

ĐÁNH GIÁ NỘI DUNG 0.0/5 0 lượt đánh giá
Bạn thấy nội dung này thế nào?
Mỗi trình duyệt/tài khoản được chấm lại sau 24 giờ.
Báo bài lỗiGiúp MT.Net.VN phát hiện nội dung cần kiểm tra
Báo lỗi được ghi vào hệ thống để Admin kiểm tra. Không dùng chức năng này để gửi hỗ trợ cá nhân.
Home Dịch vụ Khóa học CPanel