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

RESPONSE IN CONSOLE => [{"id":"23","name":"fhfhfh",}]

RWAM
  • 6,760
  • 3
  • 32
  • 45
  • Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – kevin Oct 27 '20 at 13:31
  • Could you provide a few more details? – xforfun Oct 27 '20 at 13:45

2 Answers2

0

You need to parse the JSON response as below:

$(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. 



            });
        });

Then you can use it by iterating loop or anything else as per your need.

Thanks and hopefully it helps you!

Rohit Mittal
  • 2,064
  • 2
  • 8
  • 18
0

try this code:

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