无法显示ajax响应

时间:2017-08-25 04:41:51

标签: javascript ajax

这是我的javascript函数,它从以下链接中提取数据

function jsonCall1() {

        $.post("http://tallentex.com/phpwebservices/feedbackapp/index.php/hostel_service/syncData", { id: 0 }, function (data) {
            var tbl=$("<table/>").attr("id","mytable");
            $("#dv").append(tbl);
            for (var i = 0; i < data.length; i++) {
                var tr = "<tr>";
                var td1 = "<td>" + data[i]["id"] + "</td>";
                var td2 = "<td>" + data[i]["fno"] + "</td>";
                var td3 = "<td>" + data[i]["attn_no"] + "</td></tr>";

                $("#mytable").append(tr + td1 + td2 + td3);
            }
            console.log(data);
        });
    }

这是console中此函数的输出。我想在html表中显示此输出,并且还想使用datatable发送到服务器 在此响应中,我想在html表中显示数组数据,并且还希望将此数组数据发送到服务器

{status: 1, data: Array(4)}

data:Array(4)

0:{id: "1", fno: "16078134", hostel_id: "12345", attn_no: "0010146998", create_date: "2017-08-21 10:31:02"}

1:{id: "2", fno: "16078134", hostel_id: "12345", attn_no: "0010146998", create_date: "2017-08-21 10:31:02"}

2:{id: "3", fno: "16078134", hostel_id: "12345", attn_no: "0010146998", create_date: "2017-08-21 10:31:02"}

3:{id: "4", fno: "16078134", hostel_id: "12345", attn_no: "0010146998", create_date: "2017-08-21 10:31:02" 

1 个答案:

答案 0 :(得分:0)

function jsonCall1() {
  $.post("http://tallentex.com/phpwebservices/feedbackapp/index.php/hostel_service/syncData", { id: 0 }, function (data) {
    var tbl=$("<table/>").attr("id","mytable");
    $("#dv").append(tbl);
    for (var i = 0; i < data.length; i++) {
      var str = `<tr>
                   <td>${data[i].id}</td>
                   <td>${data[i].fno}</td>
                   <td>${data[i].attn_no}</td>
                 </tr>`;
      $("#mytable").append(str);
    }
    console.log(data);
 });
}