加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax处理Json数据

发布时间:2020-12-16 00:17:15 所属栏目:百科 来源:网络整理
导读:function ajaxRequestTimerCallback(id) { createXMLHttpRequest(); var url = "../TheGeneralAJAX/Display.ashx"; xmlhttp.open("post",url,true); xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlhttp.send("id=" + i
function ajaxRequestTimerCallback(id) {
            createXMLHttpRequest();
            var url = "../TheGeneralAJAX/Display.ashx";
            xmlhttp.open("post",url,true);
            xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            xmlhttp.send("id=" + id + "");
            xmlhttp.onreadystatechange = function (date) {
                if (xmlhttp.readyState == 4) {
                    var json = JSON.parse(xmlhttp.responseText);
                    if (json[0].bl) {
                        $("#show").html(json[0].strHTML);
                    }
                }
            }
        } 
var xmlhttp;
function createXMLHttpRequest() {
        if (window.ActiveXObject) {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        }
    }
public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        string strID = context.Request["id"];
        System.Collections.Generic.List<class_Test> list = new System.Collections.Generic.List<class_Test>() { 
            new class_Test(){ bl=true,strHTML=getHTML(strID)}
        };
        //将对象序列化成json格式的另外一种方法
        System.Web.Script.Serialization.JavaScriptSerializer javascriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
        string str = javascriptSerializer.Serialize(list);
        context.Response.Write(str);}
public class class_Test 
{ 
public bool bl { get; set; }
public string strHTML { get; set; } 
}


 


刚不久在以前代码里看到的,也不记得看到哪篇文章,然后写的,先记下来

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读