【发布时间】:2014-03-06 16:06:49
【问题描述】:
我有这个 ajax 调用:
<script src="js/jquery-1.11.0.js"></script>
<script type="text/javascript">
$(document).ready(function () {
// Add the page method call as an onclick handler for the div.
$("#Result").click(function () {
$.ajax({
type: "POST",
url: "Default.aspx/GetDate",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
// Replace the div's content with the page method's return.
$("#Result").html(msg.d);
}
});
});
});
</script>
HTML:
<div id="Result">Click here for the time.</div>
网络方法:
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)>
Public Shared Function GetDate() As String
Return DateTime.Now.ToString()
End Function
当我运行它时,我在控制台中遇到错误:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
谁能说出我哪里出错了?如果我下载提供的示例并且它工作正常,这在 Encosia 的 example 中提到。
【问题讨论】:
-
能否请您尝试返回 DateTime.Now.toString() 以外的静态字符串并尝试查看它是否有效?因为错误 500 表明您的服务器端存在问题.. AJAX 和 Havascript 都没有
-
实际上按钮本身没有触发...
-
500 错误表示服务器端功能正在抛出异常,您需要查找该异常是什么。来自服务器的响应正文是否包含错误消息?如果您手动加载它而不是通过 AJAX 调用,响应是什么?如果将调试器附加到服务器端代码,是否会引发异常?
-
如果在 GetDate() 函数上设置断点,它会被命中吗?
-
@David-我怎样才能找出那个异常?响应没有错误。
标签: jquery asp.net ajax vb.net