Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jqueryajax检索数据_Jquery_Ajax_Codeigniter - Fatal编程技术网

如何使用jqueryajax检索数据

如何使用jqueryajax检索数据,jquery,ajax,codeigniter,Jquery,Ajax,Codeigniter,控制台中的响应=>[{“id”:“23”,“name”:“fh”,}]您需要如下解析JSON响应: $(document).on('click','#edit',function(){ var id = $(this).attr('value'); $.ajax({ type:'post', url:"http://localhost/CI-Ajaxold/register/show/"+id, }).done

控制台中的响应=>
[{“id”:“23”,“name”:“fh”,}]

您需要如下解析
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){
        console.log(data);
    });
});
然后,您可以根据需要通过迭代循环或任何其他方式来使用它

谢谢,希望它能帮助你

请尝试以下代码:

$(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
    }});