Ajax Autocomplete for Jquery : How To Send Dynamic Parameters

前端 未结 6 1388
感情败类
感情败类 2021-01-17 22:03

i am using Ajax Autocomplete for Jquery ( http://www.devbridge.com/projects/autocomplete/jquery/ ) in one of my application. The Search Form looks something lik

6条回答
  •  长情又很酷
    2021-01-17 22:53

    As your plugins site specifies in the usage here http://www.devbridge.com/projects/autocomplete/jquery/ it has a setOptions method on the object it returns which you can use later to change options dynamically.

    Add a onchange handler on the select element and change the params options each time user selects a different value like

    $(function(){
      var ac = $('#q').autocomplete({
        serviceUrl:'/search',
        delimiter: /(,|;)\s*/, // regex or character
        maxHeight:400,
        width:325,
        zIndex: 9999,
        params: {entity_type:$('#top_search_select').val()},
        deferRequestBy: 0, //miliseconds
        noCache: false, //default is false, set to true to disable caching
        onSelect: function(value, data){window.location.replace(data);},
      });
    
      $("#top_search_select").change(function() {
          ac.setOptions({params:{entity_type:$(this).val()}});
      });
    
    
    });
    

    You should put all your code inside document ready.

提交回复
热议问题