加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ajax用法

发布时间:2020-12-15 22:02:58 所属栏目:百科 来源:网络整理
导读:JavaScript 代码 $.ajax({ type:"post",//相对于form的method url:"ajaxAction.action",//传送到的Action或URL地址 async:true,// data: {"time":time},//如果要传递多个参数{”param1”:param1,”param2”:param2,”param3”:param3} dataType:"text",// su

JavaScript代码

$.ajax({

              type:"post",//相对于form的method

              url:"ajaxAction.action",//传送到的Action或URL地址

              async:true,//

              data: {"time":time},//如果要传递多个参数{”param1”:param1,”param2”:param2,”param3”:param3}

              dataType:"text",//

              success:function(data) {//获取返回值

                document.getElementById("content").value=data; //你需要进行的业务逻辑操作

              },error:function(e) {

                alert("验证失败!");

               

              }

            });


Struts.xml配置文件

<actionname="ajaxAction" class="myAction" method="ajaxAction"></action><!—-不设置返回值 -->

Action.java方法

private ServletRequestrequest=ServletActionContext.getRequest();
private HttpServletResponseresponse = ServletActionContext.getResponse();

publicvoid ajaxTheNOCheck()throws Exception{

       try{
         String Message="返回字符串";
          response.setCharacterEncoding("utf-8");//设置编码格式
          PrintWriter writer =response.getWriter();
         writer.write(Message); //写入Message,返回值为Message里的值
          writer.close();
       }catch (Exception e) {
         e.printStackTrace();
         log.error("程序异常:",e);
         throw new Exception(e);
       }

    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读