使用AJAX获取后台数据展示在模态框中

1、传递参数  

2、ajax 

// 			/***ajax实现将表单数据填充到模态窗口中*/
			function queryPro(id) {
				$.ajax({
					url : "/TA/pro_viewUpdate.action",
					async : true,
					type : "GET",
					data : {
						"type" : "query",
						"id" : id
					},
					// 成功后开启模态框
					success : showQuery,
					error : function() {
						alert("请求失败");
					},
					dataType : "json"
				});

			}

			function showQuery(data) {
				$("#ProID").val(data.proID);
				$("#ProName").val(data.proName);
				$("#ProCode").val(data.proCode);
				$("#ChannelName").val(data.channelName);
				$("#Income").val(data.income);
				$("#UnitVal").val(data.unitVal);
				$("#DivMethod").val(data.divMethod);
				$("#BusCode").val(0);
				$("#ProStatus").val(0);
				$("#trans").val(data.allShare);
				$("#modal-form-pur").modal('show');
			}

3、后台代码

public void viewUpdate() {

		String id = ServletActionContext.getRequest().getParameter("id");
		Divide divide = divideService.findById(id);
		Date date = divide.getBonusDay();
		String  time = date.toString();
		ServletActionContext.getRequest().setAttribute("time", time);
		request.put("time", time);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/html;charset=utf-8");
		try {
			response.getWriter().write(
					JSONArray.fromObject(divide).get(0).toString());
			System.out.println(JSONArray.fromObject(divide).get(0).toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
ajax和后台传递数据的参数是json类型的数据,前台ajax代码中的data就是从后台获取到的数据,不能缺少这个参数

你可能感兴趣的:(使用AJAX获取后台数据展示在模态框中)