How can I pass an additional parameter to Jquery autocomplete in addition to "q" param
I have used jquery autocomplete 1.1 version.
I have to get list of shops for a particular 开发者_如何学JAVAcircle.
For this I have drop down list and a textbox.
Drop down list has the list of circles ,
I need to pass this "cid" as the additional parameter to the asp.net Handler where i can retrieve this "cid" and query the data base based on the text entered the the "cid".
any suggestions would be appreciated.
You can use a callback function for the autocomplete's source
option. So, all you need to do is set up a callback function that does an AJAX call itself to get the possible matches:
source: function(request, response) {
var cid = 'your cid value from where ever you get it';
$.ajax({
// Whatever AJAX options you need go here
url: '/some/place',
data: { q: request.term, cid: cid },
success: function(data) {
response(data.split('\n'));
}
});
}
The current search term is inside request.term
inside the callback. Once you have the expanded list of possible matches, call the response
function to hand it back to the autocomplete widget. For illustrative purposes I'm assuming that your server returns the matches as a list of newline separated matches, you might have to do something a little different with your real data.
I have found the solution by passing cid as the querystring.
$(document).ready(function() {
var cid = $("#ctl00_cphMain_hdnCid").val();
$("#ctl00_cphMain_txtSearch").focus();
$("#ctl00_cphMain_txtSearch").autocomplete("AutoCompleteHandler.ashx?cid=" + cid + "&storetype=1", { autoFill: false });
});
In the autocompletehandler.ashx I have retrieved the "cid" like below:
int cid = Convert.ToInt32(context.Request.QueryString["cid"].ToString().Trim());
and used this as parameter for SqlCommand
object
精彩评论