1.jsp页面javascript jquery post异步提交数据
$("document").ready(function () {
$("#menu_save").click(function () {
//取得form 里面有name的input组件 格式化value值为json串
var json = $("#menuUpdate").serialize();
alert(json);
//三个参数 1.url 2. jsonStr 3.回调函数
$.post(basePath + "updateMenu.action", json, function (data) {
if (data) {
//把返回的data转换成jquery可以解析的json对象
var datas = $.parseJSON(data);
alert(datas.result);
$("#myModal").modal("hide");
window.location.reload();
}
});
});
});
2.ajax jquery post 请求action 相应ajax 数据输出
public void updateMenu() throws IOException{
//保存注册信息
//menuService.addMenu(menu);
writer = ServletActionContext.getResponse().getWriter();
JSONObject jsonObj = new JSONObject();
jsonObj.put("result","success");
writer.write(jsonObj.toString());
}