Struts下实现ajax的小例子

7 篇文章 0 订阅
 前台
  1. var xmlHttp;
  2. function creatXMLHttpRequest() { 
  3.     if (window.ActiveXObject) { 
  4.     xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
  5.     } 
  6.     else if (window.XMLHttpRequest) { 
  7.          xmlHttp = new XMLHttpRequest(); 
  8.     } 
  9.     else { 
  10.         return
  11.       } 
  12.     }
  13. function searchName(){
  14. var name = document.getElementsByName("name")[0].value;
  15. if(name != ""){
  16.    creatXMLHttpRequest();
  17.    var url = "/kintai/kintai/action/TestAction.do?name=" + name;
  18.    xmlHttp.open("GET",url,true);
  19.    xmlHttp.onreadystatechange = tmpFind;
  20.    xmlHttp.setRequestHeader("If-Modified-Since","0");
  21.    xmlHttp.send();
  22. }else{
  23.    alert("Is not Null ");
  24. }
  25. }
  26. function tmpFind(){
  27.     if(xmlHttp.readystate == 4){
  28.          if(xmlHttp.status == 200){
  29.             var tmpName = xmlHttp.responseText;
  30.             alert(tmpName == 0?"No have the person":"the person has");
  31.   }
  32. }
  33. }
后台
  1. if(pRequest.getParameter("name") != null){
  2. String[][] conditionList = new String[1][2];
  3. conditionList[0][0] = "0";
  4. conditionList[0][1] = Common.readSqlTrans(pRequest.getParameter("name"));
  5. qryData = pDbcmd.selQureyPrep(new TestDbcl().getInfoUserAjax(), conditionList);
  6. String result = "0";
  7. if(Integer.parseInt(qryData.getRow(0).get("name"))>0){
  8. result = "1";
  9. }
  10. pResponse.setContentType("text/text;charset=UTF-8"); 
  11. PrintWriter out = pResponse.getWriter(); 
  12. out.write(result); 
  13. out.flush(); 
  14. return true ; 
  15. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值