【发布时间】:2023-03-21 17:19:01
【问题描述】:
我有一个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()
})
}));
}
我也尝试了另一个代码,但它给了我数组中的所有 td 内容
console.log($('td', table_response).map(function(_, el) {
return $(el).html()
}));
【问题讨论】:
标签: javascript jquery arrays ajax