0

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:

enter image description here

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?

ReynierPM
  • 17,594
  • 53
  • 193
  • 363
  • keyword: params.term - where do you call that function and pass the 'params' variable, the other 2 condition and field are accessed through the variables at the top, params.term is undefinded – baskin Nov 07 '16 at 14:30
  • @baskin not sure what are you talking about, can you be more clear? – ReynierPM Nov 07 '16 at 14:31
  • data: function(params) , where are you passing params in? – baskin Nov 07 '16 at 14:32
  • 1
    @baskin from [docs](https://select2.github.io/options.html#i-want-to-add-more-query-parameters-to-the-request-where-can-th) – ReynierPM Nov 07 '16 at 14:34
  • So if you are seeing it in the querystring, than the issue is not with the plugin, but the serverside. – epascarello Nov 07 '16 at 14:39
  • 1
    weird indeed, perhaps some Rewrite rule getting in the middle, like this one was http://stackoverflow.com/questions/3733454/zend-frameworks-getrequest-getquery-wont-bring-query-string-on-localhost – arhak Nov 07 '16 at 14:57
  • 1
    @arhak you're right I've tried the solution in that post and it works. – ReynierPM Nov 07 '16 at 15:00

0 Answers0