Ho visto molti problemi su questo argomento, ma mai questo. Sono in grado di chiamare questo servizio Web dalla finestra del browser, ma ottengo l'errore da AJAX. Ricevo l'eccezione di errore interno del server (500). Potrebbe essere necessario fare qualcosa con il mio URL in JQuery, dal momento che mi sto collegando da localhost. Ecco (una versione semplificata) dei miei WS:JQuery - servizi Web ASP.NET (.asmx) - errore interno del server (500)
<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
Ed ecco la mia 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);
Grazie!
Provate con '' static' parola chiave public static function (...) '. –
@DKM No ... Non sono consentite funzioni statiche per le classi di servizi Web. – lucafik
Se si ha un errore '500', suppongo che il problema sia dal lato server. – anmarti