2014-12-07:ajax学习

AJAX学习:

JSP: function ajax(){

   var xmlhttp;

   if(window.XMLHttpRequest){ //创建XMLHTTPrequest对象:ie5,ie6用Microsoft.XMLHTTP

      xmlhttp = new XMLHttpRequest();

   }else{

      ActiveObject("Microsoft.XMLHTTP");

  

   }

   xmlhttp.open("POST","basicinformation_zgxx_ajaxTest.action", true);//以post方式提交,路径,是否为异步

xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");//post时:加HTTP头

   xmlhttp.send("gh=132&id=2");//传值仅用于post,get直接在路径上写

   xmlhttp.onreadystatechange=function(){//准备状态改变时

   if(xmlhttp.readyState==4&&xmlhttp.status==200)//表示已经响应就绪

      {

         alert(xmlhttp.responseText);//得到后台传的值

      }

   }

   }

后台:

public voidajaxTest(){

      System.out.println("+++"+gh);

      HttpServletResponsere =ServletActionContext.getResponse();

      re.setCharacterEncoding("UTF-8");// 指定返回值的编码方式,必须放在out声明之前

      re.setContentType("text/html;charset=UTF-8");

      PrintWriterpw = null;

      Stringstr = "ajax传输";

      try {

         pw= re.getWriter();

         pw.append(str);

         pw.flush();

      }catch(IOException e) {

         e.printStackTrace();

      }finally{

         pw.close();

      }

     

     

     

   }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值