In Laravel Blade I have a script for searching
<script type="text/javascript">
$.ajax({
type: "POST",
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url: "{{ URL::asset('upload-panel/search')}}",
data: dataString,
dataType:"JSON",
cache: false,
success: function(result) {
var FinalResult=result.CallDetails
num_rows = result.length;
console.log(result)
},error:function(x,e) {
setTimeout(function() {searchPhoneCalls();}, 2000);
}
})
</script>
search function in controller returns is below
return json_encode($users);
In console am getting the result as an array like below
0: {Short_name: "GO120762", Date: "21-01-2020"}
1: {Short_name: "GO120764", Date: "21-01-2020"}
2: {Short_name: "GO120766", Date: "21-01-2020"}
I want to display those result in a HTML table like below
+----------+------------+
| Name | Date |
+----------+------------+
| GO120762 | 21-01-2020 |
+----------+------------+
| GO120764 | 21-01-2020 |
+----------+------------+
| GO120766 | 21-01-2020 |
+----------+------------+
3
Answers
It has nothing to deal with Laravel, it’s pure HTML / jQuery “problem”.
There is no such key named
CallDetails
exists in received JSONYou can build an array in your HTML :
And in your JS :
In your blade:
IN ajax script:
Try like this