jquery ajax提交,Jquery ajax异步提交

Ajax原生方法:

function delStudent(studentid){

$.ajax({

url:"/project/studentRpc/"+studentid+"/deleteStudentById.json",

type:"get",

dataType: 'json',

success:function(data){

var isDeleted= data.content.successed;

alert(typeof isDeleted);

if(isDeleted==true){

alert("删除成功");

window.location.reload();

}

}

});

}

dataType:'json' 设置返回值类型

contentType:"application/x-www-form-urlencoded"(默认值)

contentType参考文章:

页面采用回调函数function(data) 处理后台返回的结果

a标签onclick事件触发加入秒杀

前台function addproduct(id){

var mprice=document.getElementById("mprice_"+id).value;

var number=document.getElementById("number_"+id).value;

var sid=document.getElementById("special.id").value;

if (mprice==""){

alert("请输入特价价格");

return false;

}else if (number==""){

alert("请输入特价数量 ");

return false;

}else {

//重点在这儿

$.get("${ctx}/special/addProduct.action?specialVo.quantity="+number+"&specialVo.memberPrice="+mprice+"&specialVo.id="+id+"&special.id="+sid,

function(data){

if(data=="true"){

alert("添加成功");

window.location.reload();

}

})

/* window.location.href="${ctx}/special/addProduct.action?specialVo.quantity="+number+"&specialVo.memberPrice="+mprice+"&specialVo.id="+id+"&special.id="+sid; */

}

}

后台public void addProduct(){

PrintWriter out=null;

try {

System.out.println(specialVo.getQuantity());

System.out.println(specialVo.getMemberPrice());

System.out.println(specialVo.getId());

System.out.println(special.getId());

HttpServletResponse response=ServletActionContext.getResponse();

out=response.getWriter();

out.print(true);

out.flush();

out.close();

} catch (Exception e) {

e.printStackTrace();

out.flush();

out.close();

out.println(0);

}

}

struts配置action无需result

方法有两种,一是返回无类型,即void类型,二是返回Action.NONE(String类型)当是这两种类型的时候,struts2就不会对result进行主动处理了

即我们只需要在action方法中,处理ajax调用,而返回void或者"none"就行了

参考文章:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值