且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JSON编码MySQL结果,然后使用jQuery读取

更新时间: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');