How to fetch data in to datatables using jquery and ajax

by Naga Phaneendra   Last Updated February 11, 2019 09:24 AM

i have written code to post a values to getdata.php file and from that file i am getting some data in the format. i write a script code like this.

function getId(val) {

      $.ajax({
            type:'POST',
            url:'getdata.php',
            data:'text1='+val,
            success:function(html){
                $('#city').html(html);

             }
        });
 }

and the php file look like this

<?php
 $text1 = $_POST['text1'];

  include("config.php");
  $sql = "SELECT tbname FROM vehicle WHERE vid = '$text1'";
  $result = mysqli_query($db,$sql);
  $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  $count = mysqli_num_rows($result);
  foreach ($result as $vehicle){
   $tbname = $vehicle["tbname"];
   //echo $tbname;
   }
  $sql = "SELECT * FROM $tbname  WHERE vid = '$text1'";
  $result1 = mysqli_query($db,$sql);


    while($data = mysqli_fetch_array($result1)){
            echo "<tr>
                <td>".$data['id']."</td>
                <td>".$data['vid']."</td>
                <td>".$data['date']."</td>
                <td>".$data['latitude']."</td>
                <td>".$data['longitude']."</td>
                <td>".$data['speed']."</td>
                <td>".$data['batery']."</td>
                <td>".$data['totalkm']."</td>
                <td>".$data['intrkm']."</td>
                <td>".$data['control']."</td>
            </tr>";

          }

      ?>

i am getting data from server ,it is fine.But i want to put the comming result from php file in to datatables.how to change my script code to append data to datatables. i want this result to be in datatables. please help me.



Related Questions


Ajax call to wcf is returning undefined

Updated May 08, 2019 16:24 PM



StackOverflow is not working with AJAX

Updated February 09, 2019 12:24 PM