How to debug and find error code with json and ajax

Description

How to debug json code. How to used console.log function.output return null value for other file used json ajax debug. How to check and debug the error, output for next file using ajax and json. how to debug data for using json and ajax in php

 

How to used and debug getJSON with console.log() and alert function to output json structure 

console output show in the browser 

console.log( ); used to check the out for next file 

for example

console.log(data);

 

console output show and check in firebug console option 

press F12 and bottom side show option console

and 2nd option used to alert() function 

for example 

alert(data);

alert(sub);

 

 

<script>  

 $(document).ready(function(){  

  $("#batchselect").click(function() { 

       var htmcont;

  var txt = $("#batchselect").val();            

//alert(txt);

$.getJSON('followupaddsearch.php',{'batchselect':txt}, function(data) {

//alert(data);

htmcont = "";

var id = data.id; 

var sub = data.sub; 

 //alert(sub); 

 console.log(data); 

htmcont += '<div style="width:400px;" >';

htmcont += '<input class="form-control boxed" id="inputaddname1" name="" value="'+sub+'" type="text">';

htmcont += '</div>';

$("#resultbatchselect").html(htmcont);

    });

});

 });  

 </script> 

<div style="width:200px; float:left">

         <select class="form-control" id="batchselect" >

<?php

$showst=mysql_query("Select * from batch");

   while($rowlinkst=mysql_fetch_array($showst)){?> 

<option value="<?php echo $rowlinkst['id']; ?>,<?php echo $rowlinkst['batchcode']; ?>"><?php echo $rowlinkst['batchname']; ?></option>

<?php } ?>

</select>

</div>

<div style="width:200px; float:left" id="resultbatchselect">

<input type="text" class="form-control boxed" id="inputaddname1" name="" value="">

</div>

</div>

 

 

 

followupaddsearch.php

 

<?php

//include("config.php");

$batchselect =  $_GET['batchselect']; 

 

//echo $batchselect;

 

$batchselectidc = explode(",", $batchselect);

    $batchselectid = $batchselectidc[0];

$batchselectname = $batchselectidc[1];

    ?>

<?php

 

$showst=mysql_query("SELECT * FROM subject where batchcodeid = '".$batchselectid."'");

$rowlinkst=mysql_fetch_array($showst);

 

$data = array();

   $data = array(    

   'id' => $rowlinkst['id'],   

   'sub' => $rowlinkst['sub']   

   );

 //$data =   $batchselect 

  // $data = "SELECT * FROM subject where batchcodeid = '".$batchselectid."' order by id desc limit 1";

 echo json_encode($data);    

  ?>