Response title
This is preview!
This already works ...
In asp code behind :
[
WebMethod] public static string GetCMSVendorIDs(string term){
Database db1 = DatabaseFactory.CreateDatabase("GenesisAccountsConnectionString"); DbCommand cmd1 = db1.GetSqlStringCommand( String.Format(@"SELECT TOP 25 Something from Somewhere where id like '%{0}%' ", term)); DataSet ds = db1.ExecuteDataSet(cmd1); var data = ds.Tables[0].AsEnumerable().Select(s => s.Field<string>("something")); JArray arr = new JArray(data); return arr.ToString();}
Client Script :
var
cmsVendCache = {};$(
'#ctrl).autocomplete({minLength: 2,
source:
function(request, response) { if (cmsVendCache.term == request.term && cmsVendCache.content) {response(cmsVendCache.content);
}
if (new RegExp(cmsVendCache.term).test(request.term) && cmsVendCache.content && cmsVendCache.content.length < 13) { var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");response($.grep(cmsVendCache.content,
function(value) { return matcher.test(value.value)}));
}
$.ajax({
type:
"POST",data: JSON.stringify(request),
url:
"mypage.aspx/mymethod",contentType:
"application/json; charset=utf-8",success:
function(data) {cmsVendCache.term = request.term;
response(JSON.parse(data.d));
}
})
}
});
$(document).ready(function () { $("#Text1").autocomplete({ minLength: 1, source: function (request, response) { if (cmsVendCache.term == request.term && cmsVendCache.content) { response(cmsVendCache.content); } else if (new RegExp(cmsVendCache.term).test(request.term) && cmsVendCache.content) { var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i"); response($.grep(cmsVendCache.content, function (value) { return matcher.test(value) })); } else { $.ajax({ type: "POST", data: JSON.stringify(request), url: "ajaxservice.svc/searchShares", contentType: "application/json; charset=utf-8", success: function (data) { cmsVendCache.term = request.term; cmsVendCache.content = data; response(data); } }) } } }); })
© 2013 jQuery Foundation
Sponsored by and others.