使用AJAX发送POST/GET请求并处理返回的结果集

 1.AJAX格式

$.ajax({
     //请求方式post /get
	type:'post',
    //请求地址
	url:'${ctx}/business/userActivateOrder/getOrders',
    //请求数据类型
	dataType:'json',
    //传输数据
	data:{'mobile':mobile,'buyName':buyName,'orderNo':orderNo,'singleCode':singleCode},
    //是否异步
	async:false,
	success:function(data){
        var str = ""+
	    "";
    //遍历结果集
	    $.each(data, function(i,item){
		    str += "
订单号用户名电话IMEI号操作
"+item.orderNo+""+item.buyName+""+item.phone+" "+item.singleCode+"关联"; }); //将拼接的table输出到控件上 $("#model").html(str); }, error:function(){ alert("ajax调用失败"); } });

2.后台接收参数并返回结果方式

@RequestMapping(value = "getOrders", method = RequestMethod.POST, headers = { "Accept=application/json;charset=UTF-8" })
@ResponseBody
public String getOrdersByOrderNo(
	@RequestParam(value = "mobile") String mobile,
	@RequestParam(value = "buyName") String buyName,
	@RequestParam(value = "orderNo") String orderNo,
	@RequestParam(value = "singleCode") String singleCode) {
		UserActivateOrder userActivateOrder = new UserActivateOrder();
		userActivateOrder.setMobile(mobile);
		userActivateOrder.setBuyName(buyName);
		userActivateOrder.setOrderNo(orderNo);
		userActivateOrder.setSingleCode(singleCode);
		List order = 
           userActivateOrderService.findOrders(userActivateOrder);
	return JSON.toJSONString(order);
}

 

你可能感兴趣的:(jsp,js,jQuery)