vjame

          優化代碼是無止境的
          隨筆 - 65, 文章 - 9, 評論 - 26, 引用 - 0

          導航

          <2011年6月>
          2930311234
          567891011
          12131415161718
          19202122232425
          262728293012
          3456789

          公告

          子曰:“學而時習之,不亦說乎?有朋自遠方來,不亦樂乎?人不知,而不慍,不亦君子乎?”

          常用鏈接

          留言簿(5)

          我參與的團隊

          隨筆分類

          隨筆檔案

          文章檔案

          積分與排名

          • 積分 - 73609
          • 排名 - 756

          最新評論

          閱讀排行榜

          js處理服務器返回的對象

          格式一:
          {
          firstname:"Bruce",
          lastname:"Perry",
          gender:"M",
          country:"USA"
          }

          代碼片段:

          function handleJson(  ){
              
          if(request.readyState == 4){
                  
          if(request.status == 200){
                      
          var resp =  request.responseText;
                      
          var func = new Function("return "+resp);
                      
          var objt = func(  );
                      
          var div = document.getElementById("json");
                      stylizeDiv(resp,div);
                      div 
          = document.getElementById("props");
                      div.innerHTML
          ="<h4>In object form</h4>"+
                                    
          "<h5>Properties</h5>firstname= "+
                                    objt.firstname 
          +"<br />lastname="+
                                    objt.lastname
          + "<br />gender="+
                                    objt.gender
          + "<br />country="+
                                    objt.country;
                  } 
          else {
                      alert(
          "A problem occurred with communicating between "+
                           
          "the XMLHttpRequest object and the server program.");
                  }
              }
          //end outer if
          }

           


          格式二:

          [
           "basketball","football"
          ]


          代碼片段:

          //event handler for XMLHttpRequest
          function handleResponse(){
              
          try{
                  
          if(request.readyState == 4){
                      
          if(request.status == 200){
                          
          var resp =  request.responseText;
                        
                          
          if(resp != null){
                              
          //return value is a JSON array
                              var objt = eval(resp);
                              
                              createChecks(objt);
                          }

                      }
           else {
                          
          //request.status is 503  if the application isn't available;
                          //500 if the application has a bug
                          alert(
                                  
          "A problem occurred with communicating between"+
                                  
          " the XMLHttpRequest object and the server program.");
                      }

                  }
          //end outer if
              }
           catch (err)   {
                  alert(
          "It does not appear that the server "+
                        
          "is available for this application. Please"+
                        
          " try again very soon. \nError: "+err.message);

              }

          }




           

          posted on 2011-06-08 11:15 lanjh 閱讀(431) 評論(0)  編輯  收藏 所屬分類: Java Web

          主站蜘蛛池模板: 兴文县| 宝山区| 建水县| 象山县| 靖宇县| 隆德县| 华容县| 正宁县| 泽普县| 象山县| 宜城市| 浠水县| 嘉峪关市| 长治市| 应用必备| 南乐县| 上杭县| 东平县| 航空| 墨玉县| 海原县| 漠河县| 海南省| 桃江县| 海门市| 永济市| 旺苍县| 龙海市| 贡觉县| 南康市| 刚察县| 济阳县| 通江县| 泰宁县| 贺州市| 镇坪县| 赤峰市| 太仆寺旗| 清新县| 庆城县| 石泉县|