尝试发送Ajax消息失败消息:asp.net JavaScript的Ajax错误:未找到
我简单的aspx页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportViewer.aspx.cs" Inherits="MyProject.AspNetForms.ReportViewer" %>
<script type ="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type ="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function CleanUpSession() {
$.ajax({
type: "POST",
url: "ReportViewer.aspx/CleanUp",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{}",
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + textStatus + "\n\nError: " + errorThrown);
},
success: function (result) {
alert("We returned: " + result);
}
});
}
</script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<button OnClick="CleanUpSession();">test</button>
</body>
</html>
CS代码:
public partial class ReportViewer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string CleanUp()
{
return "My message";
}
}
如果url将“ReportViewer.aspx/CleanUp”更改为“〜/ AspNetForms/ReportViewer.aspx/Clea nUp“然后我发现异常
"The file '/AspNetForms/~/AspNetForms/ReportViewer.aspx' does not exist."
尝试'数据:{}' –
相同的结果,即使删除“数据”线,坚持错误实际上 – Ramunas
你原来的代码更正确w.r.t.数据 - 尽管我认为jquery会对数据进行jsonify –