jQuery.ajax submit 查询

1. HTML From

 <h3 >数据查询 </h3>
 <form id ="fSearch">
     <p>
         省份: <select  name ="provinceId" id="selProvince"></select>
     </p>
     <p>
         分类: <select  name ="categoryId" id ="selCategory"></select>
     </p>
     <p>
         <input type="submit" value ="查询" />
     </p>
 </form >
<table id="table-1">
    <thead>
        <tr>
            <th> 所属省份</th>
            <th> 分类</th>      
            <th></ th>
        </tr>
    </thead>
    <tbody id ="tbody-1"></tbody>
</table>

 

2. JavaScript Ajax Form

$("#fSearch").submit(function (){  
    var searchInfo = $(this).serialize();
    $.ajax({
        url: "/" , 
        type: 'Get',
        dataType: "json",
        data: searchInfo,
        traditional: true,
        success: function (result) {
            if (result.Success) {
                $("#table-1").show();
                $("#tbody-1").html("");
                $.each(result.Data, function (i, item) {
                    $( "#tbody-1").append("<tr>" +
                        "<td>" + item.ID+ "</td>" +
                        "<td>" + item.Name + "</td>" +                      
                        "<td><a href=\"#\" onclick=\"javascript:edit('" + item.ID + "')\"" +
                        "data-id=\"" + item.ID + "\" >编辑</a></td>" +
                        "</tr>");
                });
            }
        },
        error: function (error) {
        }
    });
    return false;
});

 

你可能感兴趣的:(jquery)