【问题标题】:How can I do to recieve json from jquery's ajax request in asp.net?如何在 asp.net 中从 jquery ajax 请求接收 json?
【发布时间】:2014-02-19 08:37:07
【问题描述】:
$.ajax({
    url : "Handler1.ashx",
    type : "GET",
    cache : false,
    data : {
        type : "refresh",
        point: [x:1,y:2]
    });

“类型”可以是“POST”。在“Handler1.ashx”中,我有“HttpContext”对象,那么如何从“HttpContext”对象中获取json呢?

我发现这是误解,我的意思是:

public void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "text/plain";
    // How can I get json here?
}

【问题讨论】:

    标签: jquery asp.net ajax json httpcontext


    【解决方案1】:

    类似于这个问题。 pass jquery json into asp.net 。 点击链接,它可能对你有用。

    【讨论】:

      【解决方案2】:

      需要使用success回调来捕获请求返回的数据,如下图:

       $.ajax({
           url : "Handler1.ashx",
           type : "GET",
           cache : false,
           data : {
               type : "refresh",
               point: [x:1,y:2]
           },
           success: function(responsedata){
      
                alert(responsedata); // <-- there's your data
      
           }
       });
      

      【讨论】:

        【解决方案3】:

        使用 success 回调获取您的 json 数据

        以下代码可能会对您有所帮助..

        $.ajax({
            url : "Handler1.ashx",
            type : "GET",
            cache : false,
            data : {
                type : "refresh",
                point: [x:1,y:2]
            },
            success: function(res){
                //do your code.
                //here res is your json which you return from Handler1.ashx
                console.log(res);
            }
        });
        

        【讨论】:

          猜你喜欢
          • 2013-12-30
          • 1970-01-01
          • 1970-01-01
          • 2011-08-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-10-04
          • 2013-03-11
          相关资源
          最近更新 更多