【发布时间】:2014-02-07 13:44:20
【问题描述】:
我正在通过 ajax 学习 asp 方法和...
所以我试着做ff。来自本站:http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
在JS文件中:
$(document).ready(function () {
// Add the page method call as an onclick handler for the div.
$("#Result").click(function () {
$.ajax({
type: "POST",
url: "WebForm1.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").text(msg.d);
}
});
});
});
在 aspx 中:
<html>
<head>
<title>Calling a page method with jQuery</title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="Scripts/JScript1.js"></script>
</head>
<body>
<div id="Result">Click here for the time.</div>
</body>
</html>
在代码隐藏中:
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public static string GetDate()
{
return DateTime.Now.ToString();
}
}
}
当我在本地 PC 上的 VS studio 上运行它时,它工作得很好;但是,一旦文件部署在 IIS 服务器中,当我单击容器时会出现此错误:
POST http:///WebForm1.aspx/GetDate 500(内部服务器错误)
在 IIS 中有什么需要配置的吗?还是与代码相关的错误?
【问题讨论】:
标签: jquery asp.net ajax iis webmethod