【发布时间】:2009-08-28 17:20:52
【问题描述】:
如果 HTTP 请求是 POST,则使用查询 ajax 在 ASP.NET 页面中调用 webmethod 效果很好。如果使用 HTTP GET 请求,则运行 Page_Load 事件而不是 web 方法。 有什么想法吗?
这里是阿贾克斯
$.ajax({
type: "GET",
url: "http://local.proleaguesports.pagefad.com/AjaxTesting.aspx/receivermethod",
data: "{'test':'MyName'}",
contentType: "application/json",
dataType: "json",
success: mycallback,
error: handler
});
这是 C# 中的代码
public partial class AjaxTesting : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Page_Load runs instead of the receivermethod below");
}
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public static string receivermethod()
{
return "test received";
}
}
【问题讨论】:
-
你为什么使用Get?如果您在 Internet 上进行一些阅读,您会发现它会带来一些重大的安全漏洞。 “发布”不起作用吗?
-
John,你能推荐一篇好的安全和 HTTPGET 文章吗?我想我会使用 POST。但是,现在我很好奇:)
-
您的 ajax 调用正在传回数据,但您的 WebMethod 没有参数