Ajax
Posted 1582277142
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ajax相关的知识,希望对你有一定的参考价值。
前台:
$.ajax({
type: ‘POST‘,
url:
‘/admin/mall/category-add-edit.htm?ajax=‘+"ajax",
data: "categoryId=" +
categoryFormid+"&city="+city,
success: function(msg){
//alert(msg);
if(msg==undefined || msg==null ||msg==""){
return ;
}
var jo=eval(‘(‘+msg+‘)‘);
//1百分比 2固定值
$("#charge_type").val(jo.charge_type);
if(jo.charge_type==1){
document.getElementById(‘type1‘).style.display="";
document.getElementById(‘type2‘).style.display="none";
}
if(jo.charge_type==2){
document.getElementById(‘type1‘).style.display="none";
document.getElementById(‘type2‘).style.display="";
}
}
})
后台:
Long categoryId =
ControllerUtils.getLongParameter(map, "categoryId",
request);
response.setContentType("text/html;charset=GBK");
PrintWriter out = response.getWriter();
JSONObject jsonO=new
JSONObject();
GoodsCategoryExt
charge_type=extService.getExt(categoryId, "charge_type");
GoodsCategoryExt fixTip=extService.getExt(categoryId, "fixTip");
GoodsCategoryExt fee=extService.getExt(categoryId, "fee");
jsonO.put("charge_type", charge_type.getExt_str());
jsonO.put("fixTip", fixTip.getExt_str());
jsonO.put("fee",
fee.getExt_str());
out.print(jsonO.toString());
out.flush();
out.close();
return null; //这里必须return null; 否则会return mv等信息,对返回的信息进行干扰
或者
response.setCharacterEncoding("UTF-8");
response.getWriter().write("exist");
response.flushBuffer();
return null;
以上是关于Ajax的主要内容,如果未能解决你的问题,请参考以下文章