1

这个问题是参考我的另一个问题Auto complete not working。这个问题在我的代码中仍然存在,但我想以其他方式这样做。我正在考虑从另一个 javascript 函数调用我的 web 服务,并将从服务返回的值传递给这个自动完成函数,因为当我尝试将一些虚拟值传递给这个 jquery 函数时,它运行良好。我不确定它是否没有调用我的网络服务。

虽然现在我已经编写了另一个函数来调用我的服务并获取请求 -

        function SendRequest() 
    {
    debugger;
        SearchIssues.GetServerResponse(document.getElementById('ctl00_ContentPlaceHolder1_txtIssueNo').value, OnComplete, OnError, OnTimeOut);
    }
    function OnComplete(arg)
    {
        alert(arg);
    }
    function OnTimeOut(arg)
    {
        alert("timeOut has occured");
    }
    function OnError(arg)
    {
        alert("error has occured: " + arg._message);
    }

在脚本管理器标签中,我添加了我的网络服务的参考 -

<asp:ScriptManager ID="ScriptManager1" runat="server">
        <Services>
            <asp:ServiceReference Path="~/SearchIssues.asmx" />
        </Services>
    </asp:ScriptManager>

我已将我的自动完成功能更新为 -

 $(function() {
   debugger;
        $(".tb").autocomplete({
            source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]  });});

在这里,我在源中传递了虚拟数据,它工作正常。

我的网络服务的签名是 -

    [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public List<string> GetCompletionList(string prefixText)
        {....
}

但它仍然没有调用我的网络服务并返回一些javascript错误 -

搜索问题未定义

请帮忙谢谢

在此处输入图像描述

4

2 回答 2

0

1>我认为在打电话时你应该有完整的命名空间

 NameSpace.SearchIssues.GetServerResponse(document.getElementById('ctl00_ContentPlaceHolder1_txtIssueNo').value, OnComplete, OnError, OnTimeOut)

2>您的服务类必须具有[ScriptService]属性。

3> 测试服务的相对 URL

“~/SearchIssues.asmx”

于 2012-08-03T11:49:19.290 回答
0

这对我有用

 [WebMethod]
            public static Array GetCompletionList(string code)
    {
    .....your code
    }


 $.ajax({
                type: "POST",
                url: "CompletionList.aspx/GetCompletionList",
                data: '{"code1":"' +code1 + '"}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (c2) {
                   ....your code
                    });

});
于 2012-08-03T14:12:36.040 回答