jQuery Autocomplete using extraParams to pass additional GET variables
I am using the autocomplete function that is now part of jquery ui.Passing an 'extraParams' field does not work but you can just append the values in the request query string.
$(document).ready(function() { src = 'http://domain.com/index.php'; // Load the cities straight from the server, passing the country as an extra param $("#city_id").autocomplete({ source: function(request, response) { $.ajax({ url: src, dataType: "json", data: { term : request.term, country_id : $("#country_id").val() }, success: function(data) { response(data); } }); }, min_length: 3, delay: 300 });});
Try this:
$('.ajax-auto input').setOptions({ extraParams: { search_type: function(){ return $(this).attr('name'); } }})
See also here
You can use the built in jquery ui autocomplete like so:
$(function() { $("#BurroughName").autocomplete({ minLength: 0, source: function( request, response) { $.ajax({ url: "/JsonData/GetBurroughFromSearchTermJson", dataType: "json", data: { term: request.term, CityId: $("#CityId").val() }, success: function( data ) { response( data ); } }); }, select: function( event, ui) { $("#BurroughId").val(ui.item.id); if (ui.item.id != null) { var cityId = $('#CityId').val(); $.getJSON("/AdSales/City.mvc/GetCityJSONListFromBrand", { burroughId: ui.item.id }, function(data) { $("#CityId").fillSelect(data); var foo = $("#CityId option[value=" + cityId + "]"); if(($("#CityId option[value=" + cityId + "]").length > 0) && cityId != "") { $("#CityId").val(cityId); } }); } $('#burroughSpinner').fadeOut('slow', function(){}); } }); });
Here's their jsonp example: http://jqueryui.com/demos/autocomplete/#remote-jsonp