Ajax url function: call not properly executed on first call (url sent is "function(param){ ..."
Ajax url function: call not properly executed on first call (url sent is "function(param){ ..."
Hello
When using a setup like:
var editor = new $.fn.dataTable.Editor( {
table: '#table',
idSrc: "row_id",
fields: [
{
type: 'select2',
name: 'item_id',
options: [ ],
optionsPair: {
label: 'text',
value: 'id'
},
opts: {
allowClear: false,
ajax: {
url: function(params) {
var count = 200;
var pag = params.page || 0;
return '/data/list/10';
},
dataType: 'json',
...
The first time I load the select2 (during datatable setup, datatable is not even visible yet) I see a network call with error because it is made to "http://server/function(params) {".
Also first time I open a select2 (one per row, inline editor) I see that faulty ajax call, but after that first call, when I search for more items typing in the search box all the calls are made ok to "http://server/data/list/10". I assume this is not the expected behaviour, is it?
Any clue on how to avoid that first error call?
Thanks in advance.
Best regards
Answers
Hi,
Does Select2 allow its
ajax.url
option to be given as a function? I suspect not since it appears to be taking the.toString()
value of the function.Allan
Hi allan
Thanks for your reply.
I see it works on second and next calls to ajax url. If it didn't take the function as a valid value it would not work on any call, would it?
Their documentation says that
ajax
should be an object - presumably the same as jQuery's. I don't know why it would work as a function in future. It is possible you've hit an undocumented edge case in Select2...Are you able to supply the
ajax
option as a static URL?Allan
Not without changing server logic.
I think it has something to do with not having default options
options: [ ],
I have managed to have only one faulty call, the first one. After that call I set "options" so that it has at least one value, and the rest of calls are ok now.