簡體   English   中英

從javascript函數調用webservice並存儲結果

[英]calling webservice from javascript function and storing the result

這個問題是參考我的另一個問題自動完成不起作用 我的代碼中仍然存在該問題,但我想到了另一種方法。 我正在考慮從另一個JavaScript函數調用我的Web服務,並將從服務返回的值傳遞給此自動完成功能,因為當我嘗試將一些虛擬值傳遞給此jQuery函數時,它運行良好。 我不確定y它沒有調用我的Web服務。

雖然現在我已經編寫了另一個函數來調用我的服務並獲取請求-

        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);
    }

在腳本管理器中,我添加了Web服務的引用-

<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)
        {....
}

但是它仍然沒有調用我的Web服務,並且返回一些javascript錯誤,例如-

SearchIssues未定義

請幫忙謝謝

在此處輸入圖片說明

1>我認為打電話時應該有完整的名稱空間

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

2>您的服務類必須具有[ScriptService]屬性。

3>測試服務的相對網址

“〜/ SearchIssues.asmx”

這對我有用

 [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
                    });

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM