datatable is not loading with ajax

datatable is not loading with ajax

anil1994anil1994 Posts: 2Questions: 1Answers: 0

Hi guys, I am new to ajax and datatables. I am trying to load data to datatables from ajax response> This is my code


<!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css"> <script type="text/javascript" src="/media/js/site.js?_=2ec2144600499da11df5c1cee6ac09df"> </script> <script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.12.4.js"> </script> <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"> $(document).ready(function() { $('#example').DataTable( { "ajax": 'https://datatables.net/examples/ajax/data/arrays.txt' } ); } ); </script> </head> <body> <table id="example" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Extn.</th> <th>Start date</th> <th>Salary</th> </tr> </thead> <tfoot> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Extn.</th> <th>Start date</th> <th>Salary</th> </tr> </tfoot> </table> </body> </html>

Answers

  • anil1994anil1994 Posts: 2Questions: 1Answers: 0

    Please help me asap.

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,948

    You have some syntax errors in your html. To start with you need to change the following:

        <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js">
         </script>    //<<<<add this line
         
    <script>   // <<<<add this line
    $(document).ready(function() {
        $('#example').DataTable( {
            "ajax": 'https://datatables.net/examples/ajax/data/arrays.txt'
        } );
    } );
     
     
        </script>
    

    Your page should run. However you might not be able to load the from another site. You probably will need to load it from your local server.

    Kevin

This discussion has been closed.