Jquery、Ajax和ASP.NET webmethods
如果HTTP请求是POST,则使用查询ajax在ASP.NET页面中调用webmethod效果良好。如果使用HTTP GET请求,则运行Page_Load事件,而不是webmethod。 有什么想法吗 这里是AjaxJquery、Ajax和ASP.NET webmethods,asp.net,jquery,ajax,Asp.net,Jquery,Ajax,如果HTTP请求是POST,则使用查询ajax在ASP.NET页面中调用webmethod效果良好。如果使用HTTP GET请求,则运行Page_Load事件,而不是webmethod。 有什么想法吗 这里是Ajax $.ajax({ type: "GET", url: "http://local.proleaguesports.pagefad.com/AjaxTesting.aspx/receivermethod", data: "{'test'
$.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语言中的代码#
<>你可以考虑将你的WebMead移动到一个单独的Web服务/ASMX中。我在某处听说,在aspx中调用webmethod会导致整个页面被重新加载,尽管我目前找不到对此的确认参考。为什么要使用Get?如果你在互联网上阅读,你会发现它打开了一些重要的安全漏洞。“Post”行得通吗?John,你能推荐一篇好的安全和HTTPGET文章吗?我想我会用邮局。但是,现在我很好奇:)您的ajax调用正在传回数据,但是您的WebMethod没有参数检查:没有。我有一些web方法工作得很好,不会重新加载页面。我只是在具有多个webmethods的页面的page_load方法中设置了一个断点。调用webmethod确实会触发Page_Load(),我假设这意味着其他一切。
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";
}
}