I'm trying to save code by inserting a function with the code that iterates over all the variables, but for some reason I don't understand it doesn't work for me.
This would be the complete code without the function to repeat code.
$(".Series").select2({
ajax: {
url: "Select.php?que=Series",
dataType: 'json',
data: function (params) {
return {
q: params.term // search term
};
},
processResults: function (data) {
return { results: data };
},
cache: false,
minimumResultsForSearch: Infinity,
language: "es"
}
});
What I am doing is remotely uploading json data.
And the idea is all the ajax code to pass it to an external function and pass it the variable that I want it to change.
Something like this:
$(". Series").select2({ Busquiselect('Series'); });
and in the Busquiselect function I put the code that is common for all of them.
function Busquiselect(Que) {
ajax: {
url: "Select.php?que="+Que,
dataType: 'json',
data: function (params) {
return {
q: params.term // search term
};
},
processResults: function (data) {
return { results: data };
},
cache: false,
minimumResultsForSearch: Infinity,
language: "es"
}
};
The thing is that when I run it, it gives me this error:
SyntaxError: Unexpected string literal 'Series'. Expected a parameter pattern or a ')' in parameter list.
I don't quite understand where the syntax error is, in other functions I pass parameters using the quotes and they don't give an error. Why can it be giving the error here?