I had a similar problem a few months ago, but that was easily solved because I was working on an MVC application. I’m working on an old webforms application at the moment.
I can see the proper results coming back in a debugger, but nothing is getting displayed in my textbox. I must not be formatting the results properly. This is difficult, because WebForms doesn’t have a built-in serializer for JSON (to my knowledge). So instead, I’m returning pipe-delimited content, and then splitting it on return.
My javascript…
function myAutoComplete(myTextBox, myLabel, myHiddenVar) {
$(myTextBox).autocomplete({
source: function (request, response) {
$.ajax({
type: 'POST',
dataType: 'json',
url: "myAutoCompletePage.aspx?q=" + request.term +
"&mySearchType=" + $(myLabel).html(),
success: function (data) {
response($.map(data, function (item) {
var result = item.split("|");
return { label: result[0], value: result[0], id: result[1] }
}));
}
});
},
select: function (event, ui) {
$(myTextBox).val(ui.item.name);
$(myHiddenVar).val(ui.item.id);
return false;
}
});
}
My code-behind…
foreach (DataRow myDataRow in myDataTable.Rows)
{
Response.Write(myDataRow[0].ToString() + "|" + myDataRow[1].ToString() + Environment.NewLine);
}
Response.End();
You should use (your response is not valid JSON) :