当我尝试从脚本访问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;
}
}
答案 0 :(得分:0)
在.asmx代码的顶部(可能是C#)尝试将以下行放在public class
声明的正上方。这是允许它从AJAX调用的。
[System.Web.Script.Services.ScriptService]