【问题标题】:Server side textbox value is always empty string in case of webservice在 Web 服务的情况下,服务器端文本框值始终为空字符串
【发布时间】:2011-12-27 14:28:29
【问题描述】:

我正在使用 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"}]}

【问题讨论】:

    标签: jquery jquery-plugins jquery-autocomplete jquery-tokeninput


    【解决方案1】:

    根据the documentation,您的 JSON 数组格式不正确。应该是:

    [
        {"id":"856","name":"House"},
        {"id":"1035","name":"Desperate Housewives"},
        ...
    ]
    

    你有Id,它应该是id

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-16
      • 2020-03-20
      相关资源
      最近更新 更多