我在这个主题上看到了很多问题,但从来没有这个问题。我可以从浏览器窗口调用此 Web 服务,但我从 AJAX 收到错误消息。我收到内部服务器错误异常 (500)。它可能与我在 JQuery 中的 URL 相关,因为我是从 localhost 连接的。这是我的 WS 的(简化版):
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/webdienst/_default")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class _default
Inherits System.Web.Services.WebService
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.JSON)> _
Public Function getOrganizerEventsJSON(ByVal strUser As String, ByVal strPasswort As String) As TEvent
Dim t As TEvent
'I get the event for the specified username and password
Return t
End Function
End Class
这是我的 JS:
var ASMX = "http://localhost:56035/default.asmx/";
jQuery.callAsmx = function (method, data, onSuccess, onError) {
var url = ASMX + method;
return $.ajax({
type: "POST",
url: url,
data: $.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (typeof onSuccess == "function") {
onSuccess(response.d);
}
},
error: function (msg) {
if (msg.status != 0) {
if (typeof onGlobalError == "function") {
onGlobalError([msg],
"Error while calling " + url, ERRORTYPE.error);
}
if (typeof onError == "function") {
onError(msg);
}
}
}
});
};
$.callAsmx("GetOrganizerEventsJSON", { strUser: username, strPasswort: password }, onEventsLoaded);
谢谢!