The route is shown below:
$router->get('/securityquestionlist', [ 'as'=> 'SecurityQuestionListIndexRoute', 'uses'=> 'SecurityQuestionListController@index']);
I have the following action in the controller class:
public function index()
{
$model = new SecurityQuestionListModel();
$data = $model->select('question','created_at', 'updated_at', 'status')->where('status', 1)
->orderBy('created_at', 'desc')
->paginate(3);
if(Request::ajax()){
return response()->json(['rData' => $data]);
}else{
return view('securityquestionlist.index' );
}
Below is the Ajax code:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#IdSQLTable').DataTable({
'ajax' : 'http://localhost:9901/securityquestionlist',
'cache' : false
});
} );
</script>
I get the following AJAX response from the server:
{"rData":{}}
Can someone help me, in the case of AJAX, why the value of $ data is not returned from the server. If I disable ajax and load a regular page, then the value will be received on the client side, and the data will be filled in the rows of the table. Now I have done it in:
return view('securityquestionlist.index' /* ,['rData'=> $data]*/ );
source
share