js和ajax處理方法

來源:互聯網
上載者:User

標籤:des   http   io   os   java   ar   for   sp   2014   

<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%-- <%request.setCharacterEncoding("utf-8"); %> --%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<meta name="GENERATOR" content="Microsoft FrontPage 4.0">

<title>Insert title here</title>

</head>

<script type="text/javascript">

 function getResult(stateVal) {  

   var url = "MainServlet";  

   if (window.XMLHttpRequest) {  

      req = new XMLHttpRequest();  

   } else if (window.ActiveXObject) {  

      req = new ActiveXObject("Microsoft.XMLHTTP");  

   }   

  if (req) {   

     req.open("GET", url, true);  

      req.onreadystatechange = function() {    

     if (req.readyState == 4 && req.status == 200) {     

     var result = req.responseText;     

 processor(result);     }    };    req.send(null);   }  }  function processor(result) {   var categoryTable = document.getElementById("categoryTable");      var categotys = result.split(";");   for(var i in categotys) {    if(categotys[i] == null || ‘‘ == categotys[i]) {     continue;    }    var fields = categotys[i].split(",");     var j = 0;     var tr = document.createElement("tr");     var td1 = document.createElement("td");     var td2 = document.createElement("td");     td1.innerHTML = fields[j].split(":")[1];     td2.innerHTML ="<a href=# onclick= getCategoryId(" + fields[j].split(":")[1] + ");>" + fields[j+1].split(":")[1] + "</a>";     tr.appendChild(td1);     tr.appendChild(td2);     categoryTable.appendChild(tr);   }  }  /* function descRow(categoryid) {   alert(categoryid);   getCategoryId(categoryid);   //document.body.innerHTML = document.body.innerHTML + "<br>" + result;  }  */  function getCategoryId(categoryid) {   var url = "MainCateId?state="+categoryid;   if (window.XMLHttpRequest) {    req = new XMLHttpRequest();   } else if (window.ActiveXObject) {    req = new ActiveXObject("Microsoft.XMLHTTP");   }   if (req) {    req.open("GET", url, true);    req.onreadystatechange = function() {     if (req.readyState == 4 && req.status == 200) {      var descResult = req.responseText;      productDesc(descResult);     }    };    req.send(null);   }  }  function productDesc(descResult) {   var productTable = document.getElementById("productTable");   //document.body.innerHTML = document.body.innerHTML + "<br>" + descResult;   var products = descResult.split(";");   for(var i in products) {    //id:1,categoryid:1,normalprice:3000.0,name:電視,memberprice:2000.0,descr:海信,pdate:2014-09-24 08:33:53.0;    //id:3,categoryid:1,normalprice:3000.0,name:電腦,memberprice:2000.0,descr:dell,pdate:2014-09-24 08:36:12.0;    if(products[i] == null || ‘‘ == products[i]) {     continue;    }    var fields = products[i].split(",");    for(var j in fields) {     var tr = document.createElement("tr");     var td1 = document.createElement("td");     var td2 = document.createElement("td");     td1.innerHTML = fields[j].split(":")[0];     td2.innerHTML = fields[j].split(":")[1];     tr.appendChild(td1);     tr.appendChild(td2);     productTable.appendChild(tr);    }       }  } </script>  <body onload="getResult()">

 <h1>歡迎你<%=request.getParameter("user")%></h1> <table border = ‘2‘ id=‘categoryTable‘>  <tr>   <td width="20%">編號</td>      <td width="50%">類型</td>     </tr> </table> <br><br><br> <table border =‘2‘ id =‘productTable‘> <tr>   <td width="20%">商品內容</td>      <td width="30%">商品詳情</td>   </tr> </table>  </body> </html>

js和ajax處理方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.