struts获取ajax传值,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(“删除失败”);

}

});

});

$("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代码:

Java代码 icon_copy83.gificon_star143.png

spinner83.gif

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;

}

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就行

采纳的答案

引用

data : “productType.id=productTypeId”,

data : {‘productType.id’:productTypeId}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值