ajax处理Json数据

前端之家收集整理的这篇文章主要介绍了ajax处理Json数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. function ajaxRequestTimerCallback(id) {
  2. createXMLHttpRequest();
  3. var url = "../TheGeneralAJAX/Display.ashx";
  4. xmlhttp.open("post",url,true);
  5. xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  6. xmlhttp.send("id=" + id + "");
  7. xmlhttp.onreadystatechange = function (date) {
  8. if (xmlhttp.readyState == 4) {
  9. var json = JSON.parse(xmlhttp.responseText);
  10. if (json[0].bl) {
  11. $("#show").html(json[0].strHTML);
  12. }
  13. }
  14. }
  15. }
  16. var xmlhttp;
  17. function createXMLHttpRequest() {
  18. if (window.ActiveXObject) {
  19. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  20. }
  21. else if (window.XMLHttpRequest) {
  22. xmlhttp = new XMLHttpRequest();
  23. }
  24. }
  1. public void ProcessRequest (HttpContext context) {
  2. context.Response.ContentType = "text/plain";
  3. string strID = context.Request["id"];
  4. System.Collections.Generic.List<class_Test> list = new System.Collections.Generic.List<class_Test>() {
  5. new class_Test(){ bl=true,strHTML=getHTML(strID)}
  6. };
  7. //将对象序列化成json格式的另外一种方法
  8. System.Web.Script.Serialization.JavaScriptSerializer javascriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
  9. string str = javascriptSerializer.Serialize(list);
  10. context.Response.Write(str);}
  1. public class class_Test
  2. {
  3. public bool bl { get; set; }
  4. public string strHTML { get; set; }
  5. }


  1.  


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

猜你在找的Ajax相关文章