更新时间:2023-01-16 13:53:25
在这里,我尝试给您一些想法.
Here I try to give you some idea.
使用key => value
对(如
$data = array('id' => 1, 'quat' => 10, 'id' => 2, 'quat' => 20)
,然后将其作为 json_encode()
喜欢
header('Content-type: application/json'); // don't miss it
echo json_encode(array('data' => $data));
在jQuery
In jQuery
$.post('edit/producomponentes.php',{id:id},function(response){
//READ data HERE.
console.log(response.data); // you will get a json Object
}, 'json');
^-------- set dataType as json, then you don't any extra parse effort
$.post('edit/producomponentes.php',{id:id},function(data){
$.each(data, function(index, value) {
console.log(value.componente);
console.log(value.quantidade);
});
}, 'json');