【发布时间】: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