I am using this code to sent an AJAX call within a Select2 element:
var condition_type = 'something'; // this is dynamic but I turned on a string for demonstration
var field_value = 'something_1'; // this is dynamic but I turned on a string for demonstration
$('#condition_value_1').select2({
placeholder: 'Start typing ...',
allowClear: true,
tags: true,
ajax: {
url: '/search',
dataType: 'json',
minimumInputLength: 2,
delay: 250,
data: function(params) {
return {
keyword: params.term,
condition: condition_type,
field: field_value
};
},
processResults: function(data) {
return {
results: data.items
};
}
}
});
The code above works and is sending an AJAX request with the following structure:
/search?keyword=some&condition=something&field=something_1
I should be getting three GET
parameters but instead I am getting only the last two and I am not sure why this behavior. Take a look to the debug window from phpStorm:
Notice how condition
and field
are part of the REQUEST
and are being passed as GET
parameters but where is the first one keyword
? Shouldn't be part of the REQUEST
as well? I am missing something here on the configuration either PHP or Select2?