我有一个具有1000个随机单词的自动填充功能。但是,当我开始输入内容时,我会看到一个显示错误的JavaScript弹出窗口。所以至少我知道在texbox和javascript之间存在连接,但是css剂量似乎有效。
这是我在ascx文件中的前端代码。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$(".autosuggest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "comercial/contratoGerencia.aspx/getCustomerNames",
data: "{'prefixText':'" + document.getElementById('PageContent_WebControl3_txtAutoComplete').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
}
</script>
<style type="text/css">
.autosuggest {
width: 300px;
height: 30px;
}
</style>
<asp:TextBox runat="server" ID="txtAutoComplete" CssClass="autosuggest" />
这是我的Web方法,位于代码beheind ascx文件中。
[WebMethod]
public static List<string> getCustomerNames(string prefixText)
{
List<string> employees = new List<string>();
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var stringChars = new char[8];
var random = new Random();
for (int j = 0; j < 1000; j++)
{
for (int i = 0; i < stringChars.Length; i++)
{
stringChars[i] = chars[random.Next(chars.Length)];
}
var finalString = new String(stringChars);
employees.Add(finalString);
}
return employees;
}
任何帮助都会非常好。谢谢