【问题标题】:500 (Internal Server Error) while calling webservice from jquery for autosuggest500(内部服务器错误)从 jquery 调用 web 服务以进行自动建议
【发布时间】:2014-02-22 20:21:08
【问题描述】:

当我尝试从脚本访问网络服务以进行自动建议时,我收到内部服务器 (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;
            }
        }

【问题讨论】:

  • 删除 dataType: "json" 并检查一次。
  • 您需要调试 AutoCompleteService.asmx - 在代码的早期设置断点,假设断点被命中,使用调试 (F5 - Visual Studio) 运行,单步执行 (F10) 直到发生异常 -异常应该为您提供有关问题所在的线索。
  • 服务中没有命中断点
  • 在没有 dataType:"json" 的情况下尝试过,但仍然遇到同样的错误
  • 我知道这是一个老问题。但首先您需要在 [WebMethod] 下方的 Web 服务上指定格式。我不了解 C#,但这就是它在 VB.NET 中的样子: _

标签: jquery ajax web-services autosuggest


【解决方案1】:

对不起,我迟到了,但我刚刚遇到同样的问题,我刚刚解决了如下问题。希望这会有所帮助。

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

    [System.Web.Script.Services.ScriptService]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 2013-02-23
    • 2012-05-05
    • 1970-01-01
    • 2018-01-04
    • 2013-06-02
    • 2012-01-19
    相关资源
    最近更新 更多