Ajax的简单使用方法

前端之家收集整理的这篇文章主要介绍了Ajax的简单使用方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文转自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
@H_403_239@ privateServletRequestrequest=ServletActionContext.getRequest();
  • privateHttpServletResponseresponse=ServletActionContext.getResponse();
  • publicvoidajaxTheNOCheck()throwsException{
  • try{
  • StringMessage="返回字符串";
  • response.setCharacterEncoding("utf-8");//设置编码格式
  • PrintWriterwriter=response.getWriter();
  • writer.write(Message);//写入Message,返回值为Message里的值
  • writer.close();
  • }catch(Exceptione){
  • e.printStackTrace();
  • log.error("程序异常:",e);
  • thrownewException(e);
  • }
  • }
  • 原文链接:https://www.f2er.com/ajax/164604.html

    猜你在找的Ajax相关文章