passing parameters to jQuery's select2 ajax call

Posted by Cary on Stack Overflow See other posts from Stack Overflow or by Cary
Published on 2012-11-30T01:49:07Z Indexed on 2012/11/30 5:04 UTC
Read the original article Hit count: 3083

Filed under:
|
|

I'm attempting to pass an extra parameter to an ajax call within select2:

  $(".auto-sug").select2({
    width:'element',
    minimumInputLength:2,
    ajax: {
        url: "/action/get-custom.php",
        data: function (term, page) {
          return {
              q: term, // search term
              page_limit: 10
          };
        },
        results: function (data, page) {
            return {results: data.stuff};
        }
    }
  });

I actually want to pass another parameter to the ajax call... the id of the element itself

<input type="text" class="auto-sug" name="custom" id="3383" />

however, I'm unable to figure out how to actually access the id of the element (3383) or any other value on the page.

select2: http://ivaynberg.github.com/select2/

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX