zoukankan      html  css  js  c++  java
  • day8——ajax传参到action(Struts2)

    第一种:url+?+参数

    jsp中:

    $(function(){
      $("[name='delemp']").click(function(){
      $this = $(this);
      $delid = $this.attr("delid");
      if(confirm("确认删除该条数据吗?")){
        $.ajax({
          type:"get",
          url:"deleteemployeebyid?delid="+$delid,
          dataType:"json",
          success:function(msg){
            $this.parent().parent().parent().remove();
            alert(msg);
        }
        });
      }else{
      return false;
    }
    })

    action中:

    public String delEmployeesById(){
      Map<String,Object> map = ActionContext.getContext().getParameters();
      Object[] delid = (Object[]) map.get("delid");
      String deleteid = (String) delid[0];
      Integer did = Integer.valueOf(deleteid);
      Employees emp = new Employees();
      emp.setId(did);
      employeesService.deleteEmployeeById(emp);
      return SUCCESS;
    }

    第二种:post请求传递,action属性接收(推荐

    jsp:

      ………………

      $.ajax({
          type:"post",
          url:"deleteemployeebyid,
          dataType:"json",

          data:{"delId":$delid},
          success:function(msg){
            $this.parent().parent().parent().remove();
            alert(msg);
        }

      ………………

    action:

    private Integer delId;

    getter/setter方法

    private String jsonobj;  //删除success后返回的msg

    getter/setter

    ………………具体方法中直接用delId

    struts.xml:(json结果配置)

    <!-- json响应,返回单个Object -->
    <result name="retJsonObj" type="json">
      <param name="root">jsonObj</param>
    </result>

  • 相关阅读:
    Linux的chattr与lsattr命令详解
    Ant_的最完整build.xml解释
    ant安装和验证
    MySQL ALTER TABLE: ALTER vs CHANGE vs MODIFY COLUMN
    python简单爬虫技术
    selenium自动化测试打开新标签窗口
    js中的相等与不等运算
    table-layout:fixed 属性的解说
    DWZ与KindEditor编辑器的整合
    DWZ框架学习
  • 原文地址:https://www.cnblogs.com/whisper527/p/6523313.html
Copyright © 2011-2022 走看看