$.ajax 简单记录

前端之家收集整理的这篇文章主要介绍了$.ajax 简单记录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


//页面JS

function loadInfo(){

var url=XXXXXXXXXXXX;

var params = {};

$.ajax({

type : 'POST',

url : url,

data : params,

dataType : 'json',

success : function(data) {

if(data != null){

$("#time").text(data.CYCLE_DAY);

$("#amount").text(data.STOCK_AMOUNT);

$("#money").text(data.STOCK_MONEY);

}

},

error : function(data) {

}

});

}


//后台调用

public void getCountryStock(){

StockService service = (StockService) SpringContextUtil.getBean("stockService");

HttpServletRequest request = getRequest();

String paramJson = request.getParameter("paramJson"); // 页面参数 json 形式

Map<String,String> paramsMap = new HashMap<String,String>();

paramsMap= processParams(paramJson);

List<Object> dataList = service.findMonthAndSales(paramsMap);

HttpServletResponse response = getResponse();

response.setContentType( "text/html;charset=UTF-8");

HttpSession session = request.getSession();

if(dataList != null && dataList.size() > 0){

Object object = dataList.get(0);

Object[] obj = (Object[])object;

Map<String,String> map = new HashMap<String,String>();

map.put("CYCLE_DAY",obj[0]+"");

map.put("STOCK_AMOUNT",obj[1]+"");

map.put("STOCK_MONEY",obj[2]+"");

try {

response.getWriter().write(JSONObject.fromObject(map).toString());

response.getWriter().close();

} catch (IOException e) {

e.printStackTrace();

}

}else{

try {

response.getWriter().write("");

response.getWriter().close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

原文链接:https://www.f2er.com/ajax/162691.html

猜你在找的Ajax相关文章