我有一个ajax函数,其响应是一个html表格。我需要将其转换为数组。
我的响应如下:
<table>
<tr>
<td>4362</td>
<td>Education</td>
</tr>
<tr>
<td>4373</td>
<td>Education world</td>
</tr>
</table>
我需要将这个转换成以下数组。
[['4362','Education'],['4373','Education world']]
我已完成以下ajax代码,但它没有给我精确的表单。
success:function(hasil) {
var table_response = $.parseHTML($(hasil).filter('table').html());
console.log($(table_response).each(function(index, tr) {
$('td', tr).map(function(index, td) {
return $(td).text()
})
}));
}
我尝试了另一段代码,但它将所有的内容都返回到数组中。
console.log($('td', table_response).map(function(_, el) {
return $(el).html()
}));