前台html文件:
[code=HTML]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>jQuery Autocomplete Plugin</title>
<script type="text/javascript" src="../lib/jquery.js"></script>
<script type='text/javascript' src='../jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="../jquery.autocomplete.css" />
<script type="text/javascript">
$().ready(function() {
$("#suggest4").autocomplete('../ajaxpro/ajaxtest.aspx', {
width: 300,
multiple: true,
matchContains: true,
dataType:'json',
parse: function(data) {
// alert(data);
var parsed = [];
for (var i = 0; i < data.length; i++) {
parsed[parsed.length] = {
data: data[i],
//返回的json数据:{["text":"a"},["url":"b"]}
value: data[i].text,
result: data[i].url
};
}
return parsed;
},
formatItem: function(row){
return row.text;
},
formatResult: function(row){
return row.url;
}
});
$("#suggest4").result(function(event, data, formatted) {
var hidden = $(this).parent().next().find(">:input");
hidden.val( (hidden.val() ? hidden.val() + ";" : hidden.val()) + data.url);
});
});
</script>
</head>
<body>
<h1 id="banner"><a href="http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/">jQuery Autocomplete Plugin</a> Demo</h1>
<div id="content">
<form autocomplete="off">
<p>
<label>Multiple Birds (remote):</label>
<textarea id='suggest4'></textarea>
<input type="button" value="Get Value" />
</p>
</div>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2623402-1";
urchinTracker();
</script>
</body>
</html>
[/code]
../ajaxpro/ajaxtest.aspx 后台文件内容:
[code=C#]
private string saData = @"trinity,support,android,sdk,creative,contact,forum,plaszma,sfs,warranty,zms,cell,eaer,release,firmware,phone,download,store,downloads";
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "application/json";
Response.ContentEncoding = System.Text.Encoding.UTF8;
StringBuilder dataBuilder = new StringBuilder("[");
string query = Request.QueryString["q"];
query = string.IsNullOrEmpty(query) ? "" : query;
string[] dataArray = saData.Split(',');
int num=0;
foreach (string dataStr in dataArray)
{
num++;
if (dataStr.Contains(query))
{
dataBuilder.Append("{\"text\":\"" + dataStr + "\"");
dataBuilder.Append(",\"url\":");
dataBuilder.Append("\"http://www.baidu.com?" +num.ToString());
dataBuilder.Append("\"},\n");
}
}
string resultData = dataBuilder.ToString().Trim(',')+"]";
Response.Write(resultData);
Response.Flush();
Response.End();
}
[/code]
autocomplete 插件是从官方网站上下的:http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
其实这个文件是下载包中的index.html 我只是改了从远程获取JSON数据 在FF下一切正常,但在IE下就会报 text 为空或不可识别
这是为什么?