Ajax GET请求ASP.NET页面方法?

pdr*_*pdr 11 asp.net ajax jquery post get

我本周遇到的一种情况:我们有一个jQuery Ajax调用,它返回服务器以获取数据

$.ajax(
{
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: fullMethodPath,
    data: data,
    dataType: "json",
    success: function(response) {
        successCallback(response);
    },
    error: errorCallback,
    complete: completeCallback
});
Run Code Online (Sandbox Code Playgroud)

fullMethodPath是指页面上静态方法的链接(比方说/MyPage.aspx/MyMethod).

public partial class MyPage : Page
{
    // snip

    [WebMethod]
    public static AjaxData MyMethod(string param1, int param2)
    {
        // return some data here
    }
}
Run Code Online (Sandbox Code Playgroud)

这个工作,没问题.

一位同事试图用类型为"GET"的那个替换这个电话.它坏了,我不得不解决它.最后,我回到POST,因为我们需要快速修复,但它一直在困扰我,因为在这种情况下,语义上GET更"正确".

据我所知,jQuery将数据中的对象转换为查询字符串:/MyPage.aspx/MyMethod?param1=value1&param2=value2但我可以得到的只是页面的内容MyPage.aspx.

这只是Page方法的"功能",还是有办法使GET请求有效?

SLa*_*aks 25

出于安全原因,ASP.Net AJAX页面方法仅支持POST请求.