2012-03-13 75 views
-1

我有以下阿贾克斯JSON.stringify(数据)

$.ajax({ 

    url: urlpath, 

    type: 'POST', 

    dataType: 'json', 

    data: JSON.stringify(json), 

    contentType: 'application/json; charset=utf-8', 

    success: function (data) { 

     alert(JSON.stringify(data)); 

    }, 

    error: error 

}); 

我所回传是3列的列表。当我确实警告(JSON.stringify(data))时;它显示我的数据 - 3列和4行数据。我该如何解析并将其存储到表中?

回答

1

假设你有一个表的id="my-table",你可以用类似替代的提醒:

$('#my-table tr').each(function (r) { 
     $('td', this).each(function (c) { 
      // here you cycle on every td (column) of a row to populate it 
      // example with 3 columns assuming this json structure 
      // { 
       "row1": [ 100, 200, 300], 
       "row2": [ 50, 200, 400 ], 
       "row3": [ 10, 300, 200] 
      // } 
      this.innerHTML = data["row"+r][c] 
     }) 
    }); 
  1. $('#my-table tr')...找到创建您的表行的数组
  2. $('td', this)...上的每个应用的anonimous功能td环路电流trthis充当搜索上下文的地址tds