showing results for - "onload fetch data using ajax laravel"
Timeo
27 Jan 2017
1<!doctype html>
2<html>
3   <body>
4     <input type='text' id='search' name='search' placeholder='Enter userid 1-27'><input type='button' value='Search' id='but_search'>
5     <br/>
6     <input type='button' value='Fetch all records' id='but_fetchall'>
7     
8     <table border='1' id='userTable' style='border-collapse: collapse;'>
9       <thead>
10        <tr>
11          <th>S.no</th>
12          <th>Username</th>
13          <th>Name</th>
14          <th>Email</th>
15        </tr>
16       </thead>
17       <tbody></tbody>
18     </table>
19
20     <!-- Script -->
21     <!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> --> <!-- jQuery CDN -->
22     <script src="{{asset('js/jquery-3.3.1.min.js')}}"></script>
23
24     <script type='text/javascript'>
25     $(document).ready(function(){
26
27       // Fetch all records
28       $('#but_fetchall').click(function(){
29	 fetchRecords(0);
30       });
31
32       // Search by userid
33       $('#but_search').click(function(){
34          var userid = Number($('#search').val().trim());
35				
36	  if(userid > 0){
37	    fetchRecords(userid);
38	  }
39
40       });
41
42     });
43
44     function fetchRecords(id){
45       $.ajax({
46         url: 'getUsers/'+id,
47         type: 'get',
48         dataType: 'json',
49         success: function(response){
50
51           var len = 0;
52           $('#userTable tbody').empty(); // Empty <tbody>
53           if(response['data'] != null){
54              len = response['data'].length;
55           }
56
57           if(len > 0){
58              for(var i=0; i<len; i++){
59                 var id = response['data'][i].id;
60                 var username = response['data'][i].username;
61                 var name = response['data'][i].name;
62                 var email = response['data'][i].email;
63
64                 var tr_str = "<tr>" +
65                   "<td align='center'>" + (i+1) + "</td>" +
66                   "<td align='center'>" + username + "</td>" +
67                   "<td align='center'>" + name + "</td>" +
68                   "<td align='center'>" + email + "</td>" +
69                 "</tr>";
70
71                 $("#userTable tbody").append(tr_str);
72              }
73           }else{
74              var tr_str = "<tr>" +
75                  "<td align='center' colspan='4'>No record found.</td>" +
76              "</tr>";
77
78              $("#userTable tbody").append(tr_str);
79           }
80
81         }
82       });
83     }
84     </script>
85  </body>
86</html>
queries leading to this page
ajax load table data laravelfetch data and show it in textbox with ajax jquery laravelajax fetch data in desc laravelfetch data with a jax and populate table in laravelfetch data using ajax and laravelajax call to data update and fetch record in form laravel 8foreign key checksretrieve data using ajax larave 3bhow to fetch data from controller using ajax in laravelfetching data in laravel using ajaxhow to fetch data in ajax laravelsend ajax request in laravel to fetch datafetch data and show with ajax jquery laravelget data print table in ajax in laravellaravel get data from database with ajax jqueryonload fetch data using ajax laravellaravel 8 ajax through data fetchajax and jquery fetch data in laravel without refresh pagefetch records from mysql with jquery ajax e2 80 93 laravellaravel ajax get data from databaseajax read data in laravellaravel ajax through data fetchlaravel download file via ajax requesthow to fetch data using ajax in laravelfetch data ajax laravelcall php web api from jquery laravelimage upload using ajax in laravel phpajax all data show in database for table format without refresh in laravel laravel ajax through fetch dataget data database using ajax laravelselect query laravel ajaxget laravel data in jqueryhow to feych data from database accordingly laravel ajaxlaravel get id store in database using ajaxhow to fetch data ajax laravellarvel show aready selected and show ajax dataajax script to display database results in blade view laravelhow to show data using ajax in laravelfetch data in form using ajax in laravel view value to in jquery laravel ajaxjquery ajax fetch data from database in laravelfetch laravel view data with ajaxget data onload ajax laravelajax base data fetch in laravelretrieve data from database using ajax in laravelfetch data using ajax in laravellaravel ajax load data from databaseaccess laravel data in jqueryonload fetch data using ajax laravel