日期:2014-05-17 浏览次数:20490 次
$(document).ready(function() { $("#txt_Keys").keyup(function() { var proname=$("#txt_Keys").val(); if(proname.length!=0) {alert(proname); $("autodiv").attr("style","display:block"); $.ajax( { type:"GET", url:"Handler.ashx", data:"keyword"+proname, success:function(data) { if(data!="") { <!--写到这里有点迷糊了,不知道该干啥了~--> } } }) } }) });
public void ProcessRequest (HttpContext context) { context.Response.ClearContent(); context.Response.ContentType = "text/plain"; context.Response.Cache.SetCacheability(HttpCacheability.NoCache); string proName=""; proName = context.Request["keyword"]; string sql = "select Top 10 Project_Name from UDP_Project where Project_Name like '" + proName + "'"; DataSet ds = SQLHelper.theSearch(sql); ArrayList list = new ArrayList(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { list.Add(ds.Tables[0].Rows[i].ToString().Trim()); } System.Threading.Thread.Sleep(1000); context.Response.Write(list); context.Response.End(); }
<script type="text/javascript" language="javascript"> $(document).ready(function() { $.ajax({ type: "get", contentType: "application/json", url: "returndata.aspx", success: function(data) { var data = eval("(" + data + ")"); $("#txtIMO").autocomplete(data, { minChars: 1, matchContains: true, autoFill: false, mustMatch: false, //是否完全匹配 width: 80, //宽度 formatItem: function(row, i, max) { return row.IMO; }, formatMatch: function(row, i, max) { return row.IMO; }, formatResult: function(row) { return row.IMO; } }); } }) }) </script>
------解决方案--------------------
你在那里面把数据填充到autodiv里面不就可以了 另外不要用线程 在进入时间的时候卸载掉事件 ajax请求完成或失败在绑定事件
在DotNet里面利用XML