我在这个主题上看到了很多问题,但从来没有这个问题。我可以从浏览器窗口调用此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);
谢谢!
答案 0 :(得分:2)
我有相同的错误,可以解决它:
你应该删除以下行:
contentType: "application/json; charset=utf-8",
dataType: "json",