繁体   English   中英

通过ashx处理程序传递json值:asp.net:

[英]passing json value through ashx handler: asp.net:

我正试图从ashx处理程序中获取json对象到我的js,代码如下

<script type="text/javascript">
    var path = 'Handler.ashx';

    $.ajax({
        url: path,
        dataType: 'json',
        }).success(function (data) {
            $('#content').html(JSON.stringify(data.a))
        });
</script>

和handller代码

using System;
using System.Data;
using System.Web;
using System.Linq;
using System.Collections;
using Newtonsoft.Json;

public class Handler : IHttpHandler {

    public string ProcessRequest (HttpContext context) {
        string a = "hello world";
       return JsonConvert.SerializeObject(a); 
    }

   public bool IsReusable {
        get {
            return false;
        }
}

我无法从以下代码plz中获取任何输出,请更正代码thnk u

在字符串上使用JsonConvert.SerializeObject只会返回该字符串,因为实际上没有要序列化的内容。

因此JSON.stringify(data.a)将不起作用,因为data只是字符串“ hello world”,没有名为a属性data.a将是undefined

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM