Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery - ASP.NET web services (.asmx) - internal server error (500)

I saw many problems on this topic, but never this one. I am able to call this web service from browser window, but I get the error from AJAX. I am getting Internal Server Error Exception (500). It might have to do something with my URL in JQuery, since Im connecting from localhost. Here is (a simplified version) of my 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

And here is my 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);

Thank you!

like image 213
lucafik Avatar asked Nov 02 '22 18:11

lucafik


1 Answers

I have Same error and can solved it :

you should remove below lines :

    contentType: "application/json; charset=utf-8",
    dataType: "json",
like image 150
Ali Sarshogh Avatar answered Nov 15 '22 05:11

Ali Sarshogh