使用来自jQuery ajax的C#WebMethod出错500

时间:2015-08-12 19:29:02

标签: c# jquery .net ajax

在尝试调用WebMethod时,我的ajax函数不断收到错误500.

$.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();
}

1 个答案:

答案 0 :(得分:0)

经过更多的研究后,我发现在.NET中默认禁用GET和POST。我将其添加到web.config文件中:

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

有关详细信息,请查看here

相关问题