标签:new ati reload func uri catch style result tip
1、比较正常的ajax请求;传递到后台的参数是id:1;形式
function alertModel(id){
console.log("修改的id:"+id);
$.ajax({
url: "",
type: "post",
data: {
id: id
},
success:function(data){
console.log(data);
}
});
}
2、请求的时候,参数进行处理
function saveModel(){
var p = [];
var temp = {};
temp.modelStandardName = $("#modelStandardName").val();
temp.modelFactory = $("#modelFactory").val();
temp.modelBrand = $("#modelBrand").val();
temp.modelCateName = $("#modelCateName").val();
temp.modelYear = $("#modelYear").val();
temp.modelClass = $("#modelClass").val();
temp.modelType = $("#modelType").val();
temp.modelCountry = $("#modelCountry").val();
temp.modelVouchSeat = $("#modelVouchSeat").val();
temp.modelRatedLoad = $("#modelRatedLoad").val();
temp.modelFactoryDirectPrice = $("#modelFactoryDirectPrice").val();
temp.remark = $("#remark").val();
p.push(temp);
layer.close(1);
currTc = layer.load(currTc);
$.ajax({
url:"<%=basePath%>commerical/addModel",
type:"post",
data:{
params: encodeURI(JSON.stringify(p))
},
success:function(msg){
layer.closeAll();
if (msg.success) {
layer.close(currTc);
layer.confirm(‘添加成功‘, {
btn: [‘确定‘], //按钮
yes:function(){
window.location.reload();
}
});
} else {
currTc = 0;
errorTip(msg, layer,msg.msg);
}
}
})
}
后台接收以String,接收参数;需要进行处理
@RequestMapping("/addModel")
@ResponseBody
public AjaxResult addModel(String params){
AjaxResult ajaxResult = new AjaxResult();
try {
params = URLDecoder.decode(params,"utf-8" );
JSONArray jsonArray = JSON.parseArray(params);
System.out.println(jsonArray);
int result = commericalModelService.addModel(jsonArray);
if(result > 0){
ajaxResult.setSuccess(true);
}else{
ajaxResult.setSuccess(false);
}
}catch (Exception e){
e.printStackTrace();
ajaxResult.setSuccess(false);
}
return ajaxResult;
}
标签:new ati reload func uri catch style result tip
原文地址:https://www.cnblogs.com/lazyli/p/11511147.html