Datatables always trying to get ajax as string - 1.10.15
Datatables always trying to get ajax as string - 1.10.15
I have the problem with Datatables 1.10.15 with jQuery 3.2.1, when I'm trying to add more parameters to ajax request it's always trying to get ajax as string so instead of /users/load I have [object Object] in url, I can't find any solution for this problem, my code:
var table = $('.users-listing table').DataTable({
responsive: true,
dom:
"<'row'<'col-12 col-md-6'l><'col-12 col-md-6'f>>" +
"<'row'<'col-12'tr>>" +
"<'row pagination'<'col-12 col-md-5'i><'col-12 col-md-7'p>>",
bLengthChange: false,
columnDefs: [{
defaultContent: ''
}],
pageLength: 15,
processing: true,
serverSide: true,
ajax: {
url: $(this).data('ajax-source'),
data: function ( d ) {
return $.extend( {}, d, {
'_token': window.Laravel.csrfToken
});
},
type: 'post'
}
} );
I installed Datatables as NPM package with BS4 and responsive support
When I changed in Datatables source:
url: ajax || oSettings.sAjaxSource
to
url: ($.isPlainObject( ajax ) ? ajax.url : ajax) || oSettings.sAjaxSource
url is correct but it still don't see other ajax attributes.
Am I using wrong version of Datatables or what?
Answers
I tried with CDN version of Datatables and with previous versions of jQuery 1.11 and 2.2 but it's still not working
Solved, I didn't know that data-ajax-source is DataTable attribute so I had something like this:
After I removed data-ajax-source it works
Heh - the downside of the support for data attributes! Its actually legacy the sAjaxSource option, but yes, it can get in the way like that.
Good to hear you have it working now, thanks for posting back.
Allan