简体   繁体   中英

Error 500 using C# WebMethod from jQuery ajax

I keep getting error 500 from my ajax function when trying to call WebMethod.

$.ajax({
    type: "POST",
    url: "BookingCalendar.aspx/TestFunction",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) {
        alert(msg);
    },
    error: function () {
        alert("Error");
    }
});


[WebMethod]
public static string TestFunction()
{
    return DateTime.Now.ToString();
}

After more looking I found out that GET and POST are disabled by default in .NET. I added this to the web.config file:

  <webServices>
    <protocols>
      <add name="HttpGet"/>
      <add name="HttpPost"/>
    </protocols>
  </webServices>

For more information look here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM