Good day,
How can I pass e.g: $transactions->links(); when doing an ajax call on laravel?
Heres my Controller on a normal request:
$transactions = DB::table('x_general_transactions')
->whereBetween('x_general_transactions.date_at', array($startDate,$endDate))
->paginate(30);
VIEW
{{ $transactions->(array('from' => $startDate, 'to'=>$endDate))->links() }}
and on ajax request
if (Request::ajax())
{
//$divs is my data container
$res = [$divs,$transactions->links()];
return Response::json($res);
}
so when I tried to use .load on my ajax code
$.ajax({
url: href,
type: 'get',
dataType: 'json',
success: function(response){
$('.pagination').load(response[1]);
});
});
But nothing happens, I also tried
console.log(response[1]);
ajax response:
[[[{"gt_xid":1230,"gts_xid":1231,"xid":4728,"rnr":4,"code":"OR#","link_code":"CI#","link_rnr":6,"g_type":25,"account_name":"Cash on Hand","debit":50.5,"credit":0,"description":"","date_at":"2015-10-25 16:25:19"},{"gt_xid":1230,"gts_xid":1231,"xid":4729,"rnr":4,"code":"OR#","link_code":"CI#","link_rnr":6,"g_type":25,"account_name":"Accounts Receivable - Trade","debit":0,"credit":50.5,"description":"","date_at":"2015-10-25 16:25:19"}]],{}]
result:object {}` which is empty.
I hope this helps
if (Request::ajax())
{
$res = array(
'data' => $divs,
'links' => $transactions->links()->render()
);
return Response::json($res);
}
$.ajax({
url: href,
type: 'get',
dataType: 'json',
success: function(response){
console.log(response.data);//get data
console.log(response.links);//get links
$('.pagination').load(response.data);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With