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

Ajax的简单使用方法

发布时间:2020-12-16 00:27:07 所属栏目:百科 来源:网络整理
导读:本文转自http://blog.csdn.net/kaidishi/article/details/9494443,所有权利归原作者所有。 JavaScript 代码 [javascript] view plain copy $.ajax({ type: "post" , //相对于form的method url: "ajaxAction.action" ,0); background-color:inherit">//传送

本文转自http://blog.csdn.net/kaidishi/article/details/9494443,所有权利归原作者所有。


JavaScript代码

[javascript] view plain copy
  1. $.ajax({
  2. type:"post",//相对于form的method
  3. url:"ajaxAction.action",0); background-color:inherit">//传送到的Action或URL地址
  4. async:true,0); background-color:inherit">//
  5. data:{"time":time},0); background-color:inherit">//如果要传递多个参数{”param1”:param1,”param2”:param2,”param3”:param3}
  6. dataType:"text",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> success:function(data){//获取返回值
  7. document.getElementById("content").value=data;//你需要进行的业务逻辑操作
  8. },
  9. error:function(e){
  10. alert("验证失败!");
  11. }
  12. });


Struts.xml配置文件

[html] copy
    <actionnameactionname="ajaxAction"class="myAction"method="ajaxAction"></action><!—-不设置返回值-->

Action.java方法

[java] copy
    privateServletRequestrequest=ServletActionContext.getRequest();
  1. privateHttpServletResponseresponse=ServletActionContext.getResponse();
  2. publicvoidajaxTheNOCheck()throwsException{
  3. try{
  4. StringMessage="返回字符串";
  5. response.setCharacterEncoding("utf-8");//设置编码格式
  6. PrintWriterwriter=response.getWriter();
  7. writer.write(Message);//写入Message,返回值为Message里的值
  8. writer.close();
  9. }catch(Exceptione){
  10. e.printStackTrace();
  11. log.error("程序异常:",e);
  12. thrownewException(e);
  13. }
  14. }

(编辑:李大同)

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

    推荐文章
      热点阅读