Use Ajax Json array traversal

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>廉政警句</title>
    <script src="http://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script>
    <script>
$(function () {
    $.ajax({
        url:"/lzjj/getList",
        type:'get',
    success:function (data) {
        //alert(JSON.stringify(data));
        var str = "";
        if (data != "") {
            for (var i = 0; i < data.length; i++) {
                str += "<tr><td>" + data[i].id + "</td><td>" + data[i].orgId + "</td>" +
                    "<td>" + data[i].title + "</td><td><input type='button' onclick='edit(\""+data[i].id+"\")' value='编辑'></input>" +
                    "<input type='button' onclick='del(\""+data[i].id+"\")' value='删除'></input></td></tr>";
            }
            $("#tab").append(str);
        }
    },
    dataType:"json"
});
});
function edit(id){
    alert(id);
}
    </script>
</head>
<body>
<a href="/lzjj/toAdd">添加警句</a>
<table id="tab" border="3">
    <tr>
        <td>ID</td>
        <td>ORG_ID</td>
        <td>TITLE</td>
        <td>操作</td>
    </tr>
</table>
</body>
</html>

note:
Here Insert Picture DescriptionHere Insert Picture Description

Both brackets are connected using the string + number, data [i] .id string is not necessary to use 'escape into the escape character string, function (id) method to eject alert data, and may pass parameters normally .

Guess you like

Origin blog.csdn.net/weixin_44001965/article/details/92574250