从jquery为autosuggest调用webservice时500(内部服务器错误)

时间:2014-01-30 13:37:52

标签: jquery ajax web-services autosuggest

当我尝试从脚本访问autosuggest的web服务时,我收到内部服务器(500)错误。 错误:POST localhost:4202 / Presentation / AutoCompleteService.asmx / GetAutoCompleteData 500(内部服务器错误)jquery.min.js:130

请帮助

**JQUERY** which is used for calling the service
jQuery(function () {
                $(".autosuggest").autocomplete({
                    source: function (request, response) {
                        $.ajax({
                            type: "POST",
                            contentType: "application/json; charset=utf-8",
                            url: "AutoCompleteService.asmx/GetAutoCompleteData",
                            data:"{'stationname':'" + document.getElementById('MasterContent_srctxtbx').value + "'}",
                            dataType: "json",
                            dataFilter: function (data) { return data; },
                            success: function (data) {
                                response(data.d);
                            },
                            error: function (XMLHttpRequest, result, errorThrown) {
                                alert(errorThrown);
                            } 
                        });
                    } 
                });

            });


 <td>
                        <asp:TextBox ID="srctxtbx" class="autosuggest" runat="server"></asp:TextBox>
                    </td>




[System.Web.Script.Services.ScriptService]
        public class AutoCompleteService : System.Web.Services.WebService
        {
            [WebMethod]
            public List<string> GetAutoCompleteData(string stationname)
            {
                List<string> result = new List<string>();
                DataTable traindetails = dataaccess.GetTrainDetailsForautosugget(stationname);
                for (int i = 0; i < traindetails.Rows.Count; i++)
                {

                    result.Add(traindetails.Rows[i]["Source"].ToString());

                }

                return result;
            }
        }

1 个答案:

答案 0 :(得分:0)

抱歉,我迟到了,但我刚遇到同样的问题,我刚刚解决了以下问题。希望这会有所帮助。

在.asmx代码的顶部(可能是C#)尝试将以下行放在public class声明的正上方。这是允许它从AJAX调用的。

    [System.Web.Script.Services.ScriptService]