阿贾克斯GET请求到ASP.NET页面的方法? [英] Ajax GET requests to an ASP.NET Page Method?

查看:144
本文介绍了阿贾克斯GET请求到ASP.NET页面的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跑过这周的情况:我们有一个jQuery Ajax调用的返回到服务器获取数据。

A situation I ran across this week: we have a jQuery Ajax call that goes back to the server to get data

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

fullMethodPath 是一个网页内的链接到一个静态方法(假设 /MyPage.aspx/MyMethod

fullMethodPath is a link to a static method on a page (let's say /MyPage.aspx/MyMethod).

public partial class MyPage : Page
{
    // snip

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

这工作,就没问题了。

一个同事曾试图与替换此调用其中类型是GET。它打破了,我不得不解决它。最后,我又回到了职位,因为我们需要修复快,但它一直缠着我,因为语义上一个GET在这种情况下是更正确。

A colleague had attempted to replace this call with one where type was "GET". It broke, I had to fix it. Eventually, I went back to POST because we needed the fix quick, but it has been bugging me because semantically a GET is more "correct" in this case.

据我了解,jQuery的翻译对象的数据查询字符串: /MyPage.aspx/MyMethod?param1=value1&param2=value2 ,但所有我能回来是页 MyPage.aspx

As I understand it, jQuery translates an object in data to a Query String: /MyPage.aspx/MyMethod?param1=value1&param2=value2 but all I could get back was the content of the page MyPage.aspx.

是,仅仅一个功能页的方法,或者是有一个GET请求工作的一种方式?

Is that just a "feature" of Page methods, or is there a way of making a GET request work?

推荐答案

有关安全方面的原因,ASP.Net AJAX页面的方法只支持POST请求。

For security reasons, ASP.Net AJAX page methods only support POST requests.

这篇关于阿贾克斯GET请求到ASP.NET页面的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆