1:DeliveryPersonVO对象

package com.funcanteen.business.entity.delivery.vo;

import java.util.List;
import com.funcanteen.business.entity.delivery.DeliveryPersonCampus;
import com.funcanteen.business.entity.delivery.DeliveryPersonStall; public class DeliveryPersonVO {
/**
* 校区
*/
private DeliveryPersonCampus deliveryPersonCampus;
/**
* 档口集合
*/
private List<DeliveryPersonStall> deliveryPersonStallList;
/**
* 校区集合
*/
private List<DeliveryPersonCampus> campusList;
public DeliveryPersonCampus getDeliveryPersonCampus() {
return deliveryPersonCampus;
}
public void setDeliveryPersonCampus(DeliveryPersonCampus deliveryPersonCampus) {
this.deliveryPersonCampus = deliveryPersonCampus;
}
public List<DeliveryPersonStall> getDeliveryPersonStallList() {
return deliveryPersonStallList;
}
public void setDeliveryPersonStallList(List<DeliveryPersonStall> deliveryPersonStallList) {
this.deliveryPersonStallList = deliveryPersonStallList;
}
public List<DeliveryPersonCampus> getCampusList() {
return campusList;
}
public void setCampusList(List<DeliveryPersonCampus> campusList) {
this.campusList = campusList;
} }

2:DeliveryPersonCampus 对象

package com.funcanteen.business.entity.delivery;
/**
*
* @author ckj
*
*/
public class DeliveryPersonCampus {
private Integer campusId;
private String campusName; public Integer getCampusId() {
return campusId;
}
public void setCampusId(Integer campusId) {
this.campusId = campusId;
}
public String getCampusName() {
return campusName;
}
public void setCampusName(String campusName) {
this.campusName = campusName;
} }

3:DeliveryPersonStall 对象

package com.funcanteen.business.entity.delivery;
/**
*
* @author ckj
*
*/
public class DeliveryPersonStall {
private Integer stallId;
private String stallName; public Integer getStallId() {
return stallId;
}
public void setStallId(Integer stallId) {
this.stallId = stallId;
}
public String getStallName() {
return stallName;
}
public void setStallName(String stallName) {
this.stallName = stallName;
}
}

4:DeliveryPersonCampus

package com.funcanteen.business.entity.delivery;
/**
*
* @author ckj
*
*/
public class DeliveryPersonCampus {
private Integer campusId;
private String campusName; public Integer getCampusId() {
return campusId;
}
public void setCampusId(Integer campusId) {
this.campusId = campusId;
}
public String getCampusName() {
return campusName;
}
public void setCampusName(String campusName) {
this.campusName = campusName;
} }

5jsp 页面

            <div id="addcampus" name="addcampus" class="control-group form-group" style="margin-bottom: 0">
<label class="col-md-2 control-label" style="margin-right: 14px">是否再添加校区</label>
<div class="form-group">
<select id="addCampusId" name="addCampusId" class="form-control" style="margin-bottom: 0;width:178px" onchange="queryCampusIdToStall()">
<option value="">所有</option>
<c:forEach items="${campusAllList }" var="campus">
<option value="${campus.id }">${campus.name }</option>
</c:forEach>
</select>
</div>
</div> <div id="campusAll" name="campusAll" class="control-group form-group">
<label class="col-md-2 control-label" style="margin-right: 14px">校区</label>
<div class="parent_campus" style="width:60%; float:left;">
<c:forEach items="${campusList }" var="campus">
<div style="width: 100%" class="choose_label">
<input type="checkbox" name="campusId" id="${campus.id }" value="${campus.id }" checked="checked"/>
<label for="${campus.id }">${campus.name }</label>
</div>
</c:forEach>
</div> </div>

6:ajax 请求

//点击校区获取饭堂
function queryCampusIdToStall() {
var campusId = [];
$('input[name="campusId"]').each(function(i,o){
campusId.push(o.value);
}); var addCampusId = $("#addCampusId").val();
var deliveryPersonId = $("#deliveryPersonId").val();
if (addCampusId != null && addCampusId != "") {
$.ajax({
type: "GET",
url: "<%=basePath %>delivery/deliveryperson/update!queryCampusIdToStall",
data: {
"addCampusId" : addCampusId,
"campusId": campusId,
},
dataType: "json",
success: function(data){
if (data != null) {
var campus = data.deliveryPersonCampus;
var stallList=data.deliveryPersonStallList;
var campusList = data.campusList;
//请求下拉校区重新绑定新数据
$("#addCampusId").empty();
$('#addCampusId').append($("<option>").text("所有").val(""));
for(var item in campusList){
$("#addCampusId").append($("<option>").val(campusList[item].campusId).text(campusList[item].campusName));
}
//动态添加校区和档口
addCampus(campus.campusId,campus.campusName);
for(var item in stallList){
addStall(stallList[item].stallId,stallList[item].stallName);
}
}
}
});
}
}

7:java后台代码

    /**
* ajax 请求获取档口
*
* @throws IOException
*/
public void queryCampusIdToStall() throws IOException {
HttpServletResponse response = ServletActionContext.getResponse();
DeliveryPersonVO deliveryPersonVO = new DeliveryPersonVO();
Campus campus = new Campus();
DeliveryPersonCampus deliveryPersonCampus = new DeliveryPersonCampus();
DeliveryPersonStall deliveryPersonStall = null;
List<DeliveryPersonStall> personStallList = new ArrayList<DeliveryPersonStall>();
List<DeliveryPersonCampus> personCampusList = new ArrayList<DeliveryPersonCampus>();// 动态重新封装下拉框校区数据 //获取校区
campus = campusService.load(addCampusId.longValue());
deliveryPersonCampus.setCampusId(campus.getId().intValue());
deliveryPersonCampus.setCampusName(campus.getName());
// 根据用户选择的校区ID获取档口数据档口
List<Stall> stallsList = stallService.getCampusIdToStallList(addCampusId.intValue());
if (stallsList != null && stallsList.size() > 0) {
for (Stall stall : stallsList) {
deliveryPersonStall = new DeliveryPersonStall();
deliveryPersonStall.setStallId(stall.getId().intValue());
deliveryPersonStall.setStallName(stall.getName());
personStallList.add(deliveryPersonStall);
}
}
//获取重新要加载的下拉框校区数据
List<Integer> campusIdsList = new ArrayList<Integer>();
campusIdsList.add(addCampusId.intValue());
if(campusId !=null && campusId.length>0){
for(int i=0;i<campusId.length;i++){
campusIdsList.add(campusId[i]);
}
}
List<Campus> notDeliverPersonList = campusService.getNotDeliverPersonList(campusIdsList);
for(Campus cp : notDeliverPersonList){
DeliveryPersonCampus dpc =new DeliveryPersonCampus();
dpc.setCampusId(cp.getId().intValue());
dpc.setCampusName(cp.getName());
personCampusList.add(dpc);
}
//set VO
deliveryPersonVO.setDeliveryPersonCampus(deliveryPersonCampus);//单个校区
deliveryPersonVO.setDeliveryPersonStallList(personStallList);//某校区区所有档口
deliveryPersonVO.setCampusList(personCampusList);//除以选中的所有的校区
//转JSON
String jsonString = JSON.toJSONString(deliveryPersonVO);
response.setContentType("text/plain;charset=" + "utf-8");
response.setCharacterEncoding("utf-8");
response.getWriter().write(jsonString); }

8:json格式数据

{
"campusList": [
{
"campusId": 98,
"campusName": "揭阳市职业技术学院"
},
{
"campusId": 99,
"campusName": "汕头职业技术学院"
},
{
"campusId": 100,
"campusName": "广东工商职业学院肇庆校区"
},
{
"campusId": 101,
"campusName": "岭南职业技术学院(清远校区)"
},
{
"campusId": 102,
"campusName": "测试(江门区)"
},
{
"campusId": 103,
"campusName": "测试"
}
],
"deliveryPersonCampus": {
"campusId": 12,
"campusName": "广东轻工职业技术学院(南海校区)"
},
"deliveryPersonStallList": [
{
"stallId": 56,
"stallName": "原味汤菜饭(一饭二楼)"
},
{
"stallId": 82,
"stallName": "小亨美食(一饭六楼)"
}
]
}

AJAX请求返回JSON数据动态生成html的更多相关文章

  1. 在使用Ajax请求返回json数据的时候IE浏览器弹出下载保存对话框的解决方法

    在使用Ajax请求返回json数据的时候IE浏览器弹出下载保存对话框的解决方法 最近在做一个小东西,使用kindeditor上传图片的时候,自己写了一个上传的方法,按照协议规则通过ajax返回json ...

  2. ajax请求返回json数据弹出下载框的解决方法

    将返回的Content-Type由application/json改为text/html. 在struts2下: <action name="XXXAjax" class=& ...

  3. AJAX请求,返回json进行页面绑值

    AJAX请求,返回json进行页面绑值 后台 controller @RequestMapping(value = "backjson.do",method=RequestMeth ...

  4. ashx文件结合ajax使用(返回json数据)

    ashx文件返回json数据: public void ProcessRequest(HttpContext context) { context.Response.ContentType = &qu ...

  5. Ajax前台返回JSON数据后再Controller中直接转换成类型使用,后台接收json转成实体的方法

    之前写过一篇记录文章,写的是将一个比较复杂的数据结构在前台组合起来后传递到后台. 当时并不太了解@RequestBody,也并没有使用js提供的JSON.stringify()方法 所有都是自己写的, ...

  6. jquery序列化from表单使用ajax提交返回json数据(使用struts2注解result type = json)

    1.action类引入struts2的"json-default"拦截器栈 @ParentPackage("json-default") //示例 @Paren ...

  7. js将json数据动态生成表格

    今天开发中遇到需要展示动态数据的问题, 具体要求是后端传来的json字符串,要在前端页面以table表格的形式展示, 其实没啥难的,就是拼接table标签,纯属体力活,于是自己写了个呆萌,保存起来,以 ...

  8. 使用jQuery发送POST,Ajax请求返回JSON格式数据

    问题: 使用jQuery POST提交数据到PHP文件, PHP返回的json_encode后的数组数据,但jQuery接收到的数据不能解析为JSON对象,而是字符串{"code" ...

  9. ajax请求返回json字符串/json对象 处理

    1. 返回json字符串如何处理 $.ajax({ url:xxx, success:function(date){ }, error:function(){ } }); 通过最原始的返回: Prin ...

随机推荐

  1. laravel5.1学习1-Model的创建

    laravel5.1中可以很方便的用命令行创建Model 1.php artisan make:model Content 接着添加属性 $fillable =array('id','article_ ...

  2. vue中使用vue-i18n 一个简单的国际化操作

    1.安装:npm install vue-i18n --save-dev 2.在main.js文件中引入: import VueI18n from 'vue-i18n' Vue.use(VueI18n ...

  3. 数据表设计:多对多关系E-R图转换——中间表

    链接:https://blog.csdn.net/vainfanfan/article/details/80568784 链接2:https://www.cnblogs.com/hiwangzi/p/ ...

  4. Windows上面搭建FlutterAndroid运行环境

    1.下载安装JDK https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2.配置J ...

  5. css 中 max-width 和 min-width 的区别

    max-width:规定元素本身最大宽度,即元素本身 (该div) 的宽度应小于等于其最大宽度值. min-width:规定元素本身最小宽度,即元素本身应大于等于其宽度值. 例:min-width:1 ...

  6. 一、Python概念知识点汇总

    一.编译型语言和解释性语言的区别 二.Python的设计目标 1.一门简单直观的语言并与主要竞争者一样强大 2.开源,以便使任何人都可以为它做贡献 3.代码像纯英文那样容易理解 4.适用于短期开发的日 ...

  7. java实现二维码的生成和解析:QRCode、zxing 两种方式

    第一种:QRCode.jar,使用QRCode生成和解析二维码 1.导入jar包  2.代码 (1)QRCodeUtil .java import com.swetake.util.Qrcode; i ...

  8. HDU 4825 Xor Sum(字典树)

    嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 这道题更明确的说是一道01字典树,如果ch[u][id^1]有值,那么就向下继续查找/ ...

  9. mcast_set_ttl函数

    #include <errno.h> #include <net/if.h> #include <sys/socket.h> #include <netine ...

  10. coturn服务器配置中英对比

    coturn服务器配置中英对比 默认配置位置 /etc/turnserver.conf # RFC5766-TURN-SERVER configuration file # RFC5766-TURN- ...