目前会用ashx向XMLHTTP发送JSON。那么如何用XMLHTTP向后台ashx发送XML或者JSON并解析?

解决方案 »

  1.   

    就是向后台传递json字符串,get. post都可以,然后服务端有解析json字符串的方法的google一下就好。
      

  2.   

    服务器端对服务器端有必要中间再走一次客户端吗?
    用XmlDocument 去加载?
      

  3.   

    新鲜啊?!如果浏览器端访问你的“后台”,后台怎么传递json呢?
      

  4.   

    如果浏览器端访问你的“后台”,后台怎么传递json呢  -->  如果浏览器端不访问你的“后台”,后台怎么传递json呢
    除非你说的不是浏览器端的XmlHttpRequest
      

  5.   

    说的自相矛盾
    我不知道你到底数据交换协议是XML还是Json
      

  6.   

    建议直接使用 jQuery ($.ajax 或者 $.post) 要省心的多。另外,“目前会用ashx向XMLHTTP发送JSON” 这明显是客户端取得的,服务端用 Http 协议Push 不可能。
      

  7.   

    可能我没说清楚。http://hi.csdn.net/attachment/201202/3/1319440_1328248345OTKF.jpg5到4、4到6、6到2、2到1,可以的,没问题(JSON作为交换数据格式)。现在是1到2、2到3(发送一个JSON)、3到4(接收并解析)这一步不会。script.js// 请求加载 Products 数据
    var loadProducts = function () {
     
        var xhr = getXHR();
        if (xhr == null) return;    xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {            alert("xhr.responseText: " + xhr.responseText);            var productJSON = document.getElementById("productJSON");
                productJSON.innerText = xhr.responseText;            var products = eval('([' + xhr.responseText + '])');
                
                renderProducts(products);
            }
        };
        xhr.open("GET", '/ProductHandler.ashx?action=modifyPwd', true);
        //{"id":"3266","name":"JZ12T.2-Q861A嵌入式墨绿聚晶玻璃脉熄双灶(湖北)","price":"¥604.35"} 怎么样把这一条JSON发送过去并解析接收呢?
        xhr.send();
    };
    ProductHandler.ashx        public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "application/x-javascript";
                //string action = context.Request.Params["action"]; //外部请求              String action = context.Request.Params["action"];
              
                //这里怎么接收前台传过来的JSON,并解析呢?
                context.Response.Write(GetJsonProducts());
     
                context.Response.End();          
            }
      

  8.   

    //sned发送的一个json,ashx怎么接收啊?// 请求加载 Products 数据
    var loadProducts = function () {
     
        var xhr = getXHR();
        if (xhr == null) return;    xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {            alert("xhr.responseText: " + xhr.responseText);            var productJSON = document.getElementById("productJSON");
                productJSON.innerText = xhr.responseText;            var products = eval('([' + xhr.responseText + '])');
                
                renderProducts(products);
            }
        };
        xhr.open("GET", '/ProductHandler.ashx?action=modifyPwd&count=2', true);
         
        xhr.send("{\"currPage\":2,\"idClassificacao\":\"0\",\"idGrupo\":\"0\",\"tipoOrdenacao\":\"1\",\"termoBuscado\":\"ip\",\"tipoPesquisa\":\"1\",\"buscaDescricao\":\"false\"}");};现在ashx只会接收参数
     String action = context.Request.Params["action"];