iteye_11742 2010-11-09 22:30
浏览 348
已采纳

struts 接收 jquery带参数ajax请求

 

$("input[name=#delete]").click(function(e) {
        var productTypeId = parseInt($(this).parent().parent()
                .children(".productTypeId").html());
        // var json = {
        // parameter : productTypeId
        // }
        // var strjson = JSON.stringify(json);
        alert(productTypeId);

        // var url = "controller/product/productType!deleteProductType.action";
        // var jsonObject = {
        // id : productTypeId
        // }; // JSON对象
        // var strjson = JSON.stringify(jsonObject); // 将JSON对象转变成JSON格式的字符串
        // $.post(url, {
        // json : strjson
        // }, callback);

        $.ajax({
                    url : "controller/product/productType!deleteProductType.action",
                    // dataType : "text",
                    // 这个为什么要注释掉呢?
                    data : "productType.id=productTypeId",
                    type : "post",
                    success : function(data) {
                        alert("删除成功");
                    },
                    complete : function(XMLHttpRequest, textStatus) {
                        // closeWindow();
                        alert(this);
                    },
                    error : function(data) {
                        alert("删除失败");
                    }
                });
    });

 我要把productTypeId传递给struts2 的action,action接收这个数据进行删除操作,下面是action代码:

 

public String deleteProductType() {
        // System.out.println(productType.getId());
        // JSONObject jsonObject = new JSONObject();
        // int productTypeId = Integer.parseInt(jsonObject.getJSONObject(json)
        // .getString("parameter"));
        // productTypeService.delete(ProductType.class, productTypeId);
        // System.out.println(productTypeId);
        // queryPage();
        // return "deleteProductType";
        productTypeService.delete(ProductType.class, productType.getId());
        System.out.println(productType.getId());
        return null;
    }

 控制台输出的productType.getId()为null;请朋友费心帮忙一下,只要可以让我用jquery把数据发送给action就行,即使是代码全改了;

  • 写回答

2条回答

  • yourname1111 2010-11-09 22:47
    关注

    [quote] data : "productType.id=productTypeId", [/quote]

    data : {'productType.id':productTypeId}

    一般这么用,如果还是不能获取,建议你使用modenDriven,或者是简单地在action里get,set

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员