在ASP.NET中使用Web服务进行自动完成 [英] AutoComplete using Webservice in asp.net
本文介绍了在ASP.NET中使用Web服务进行自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友,
我是Web服务的新手,我正在尝试使用jquery来自动完成文本框.以下是代码:
.aspx
Hello Friends,
I''m new to webservice''s, I''m trying out autocomplete textbox using jquery. Following is code:
.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="../JQuery/JQuery.js" type="text/javascript"></script>
<script type="text/javascript">
function lookup(inputString) {
if (inputString.length == 0) {
$("#suggestions").hide();
}
else {
$.ajax({
type: "POST",
url: "WebService.asmx/getClientName",
dataType: "json",
data: "{}",
contentType: "application/json; charset=utf-8",
success: function(data) {
if (data.length > 0) {
var datafromserver = data.d.split(",");
$("#suggestions").show();
$("#suggestionList").html(datafromserver); ''LINE1
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
}
}
</script>
<style type="text/css">
body{
font-family: Helvetica;
font-size: 13px;
color: #000;
}
h3{
margin: 0px;
padding: 0px;
}
.suggestionsBox{
position: relative;
left: 0px;
margin: 0px 0px 0px 0px;
width: 200px;
background-color: #7845DD;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border: 2px solid #000;
color: #fff;
}
.suggestionList {
margin: 0px;
padding: 0px;
}
.suggestionList li {
margin: 0px 0px 3px 0px;
padding: 3px;
cursor: pointer;
}
.suggestionList li:hover {
background-color: #DD45CD;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtAutoComplete" runat="server">
</div>
<div class="suggestionsBox" id="suggestions" style="display: none;"></div>
<div class="suggestionList" id="autoSuggestionsList"></div>
</form>
</body>
</html>
当我运行页面时,自动完成下拉菜单不起作用.知道我哪里出错了吗?
LINE1有什么问题吗?
在此先感谢
When I run the page, the autocomplete dropdown is not working. Any idea where I''m going wrong?
Is there any issue at LINE1?
Thanks in advance
推荐答案
(#suggestions").hide(); } 其他{
("#suggestions").hide(); } else {
.ajax({ 输入:"POST", 网址:"WebService.asmx/getClientName", dataType:"json", 数据: "{}", contentType:"application/json; charset = utf-8", 成功:功能(数据){ 如果(data.length> 0){ var datafromserver = data.d.split(,");
.ajax({ type: "POST", url: "WebService.asmx/getClientName", dataType: "json", data: "{}", contentType: "application/json; charset=utf-8", success: function(data) { if (data.length > 0) { var datafromserver = data.d.split(",");
(#suggestions").show();
("#suggestions").show();
这篇关于在ASP.NET中使用Web服务进行自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文