我正在使用tokenInput jquery插件进行自动完成。这个脚本运行正常
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/WebService1.asmx/HelloWorld7",
data: "{}",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) { $("#<%=demo.ClientID %>").tokenInput("http://shell.loopj.com/tokeninput/tvshows.php");
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
});
</script>
但当我更换线
$("#<%=demo.ClientID %>").tokenInput("http://shell.loopj.com/tokeninput/tvshows.php");
带
$("#<%=demo.ClientID %>").tokenInput(data.d);
它显示我自动完成,但在按钮点击事件中它将demo.Text显示为空字符串。我检查了firebug中的响应,响应是
{"d":[{"__type":"TestForMySite.fb","Id":1,"name":"ALABAMA"},{"__type":"TestForMySite.fb","Id":2,"name":"ALASKA"}]}
答案 0 :(得分:1)
根据the documentation,您的JSON数组格式不正确。它应该是:
[
{"id":"856","name":"House"},
{"id":"1035","name":"Desperate Housewives"},
...
]
您Id
应该是id
。