您的位置:首页 > Web前端 > JavaScript

html页面发送请求处理json

2015-07-01 10:10 447 查看

通过JS方式发送请求

htmlcode:

通过onclick触发

<a href="" onclick="del()" >删除</a>

<script type="text/javascript">
function del(){
if(window.confirm("是否删除?")){
$.ajaxSetup({
async : false
});
var id = document.getElementById("pid").value;
var url = "${contextPath}/publishEdit/delMsg";
var paras = {id : id};
$.get(url,paras,function(data){
if(data.RETCODE ==="1"){
alert("删除成功!")
window.location = "${contextPath}/published";
}else{
alert("删除失败!");
return;
}
});
}else{
window.location = "${contextPath}/published";
}
}
</script>


controller:

public void delMsg(){
String id = getPara("id");
boolean isDel = publishService.delContent(id);
Record r = new Record();
if(isDel){
r.set("retcode", "1");
}else {
r.set("retcode", "0");
}
renderJson(r.toJson());
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  json 发送请求