Hi,
When I use Jquery autocomplete plugin,the page doesn't show the right results at some kind of case.
First,I create a ashx page,the following is the code:
Code:
<%@ WebHandler Language="C#" Class="Autocompletedata" %>
using System;
using System.Web;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using BusinessLogicModel;
public class Autocompletedata : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string startCharacter = context.Request.QueryString["q"];
using (NorthwindEntities ctx = new NorthwindEntities())
{
string strEntitySql = "select value c from Products as c where c.ProductName like '%" + startCharacter + "%'";
ObjectQuery<Products> category = ctx.CreateQuery<Products>(strEntitySql);
context.Response.ContentType = "text/plain";
foreach (Products c in category)
context.Response.Write(c.ProductName + Environment.NewLine);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
Then,I create a aspx page:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="js/jquery-latest.js" type="text/javascript"></script>
<script src="js/jquery.autocomplete.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$("#example").autocomplete("Autocompletedata.ashx");
});
</script>
<title>搜索结果页</title>
</head>
<body>
<input id="example" />
</body>
</html>
I've used all the required
js and css document in my solution.
And run the project,and when I type a character,the textbox showed nothing, it didn't showed the results like google search.So I set the breakpoint,to follow the database,I found an odd thing: I run the sql sentence in the sqlserver2008,the result showed no row to be returned.I have my sql sentence typed below:
select Products.ProductName from
Products where
Products.ProductName='剧情片'
The result showed:
ProductName
---------------
(0 行受影响)
But I have checked the table,it did have the data,you know.how can it be possible?
I wonder if the databse field stored the chinese character,so I update my ProductName all to English words.
And Then, I run the project,and the results works well.It showed the autocomplete function just like google search.But why?Why the filed is stored chinese character,the results is quite different.
So, anybody whoever can tell me? I'm crazy by this problem.
Thanks in advance!