如何使用 jQuery ajax 检索数据

how to retrieve data using jQuery ajax

$(document).on('click','#edit',function(){
    var id = $(this).attr('value');
    
    $.ajax({
        type:'post',
        url:"http://localhost/CI-Ajaxold/register/show/"+id,
    }).done(function(data){
        console.log(data);
    });
});

控制台响应 => [{"id":"23","name":"fhfhfh",}]

您需要按如下方式解析 JSON 响应:

$(document).on('click','#edit',function(){
            var id = $(this).attr('value');
            
            $.ajax({
                type:'post',
                url:"http://localhost/CI-Ajaxold/register/show/"+id,
                
            }).done(function(data){
             let response = $.parseJSON(data);
             // here you can use response variable as needed. 



            });
        });

然后您可以根据需要通过迭代循环或其他任何方式使用它。

谢谢,希望对你有帮助!

试试这个代码:

$.ajax({
    type:'post',
    url:"http://localhost/CI-Ajaxold/register/show/"+id, 
    success: function(result){
      //use result here
    }});