Controll层返回json数据,给前端的ajax
前端代码:
function editCustomer(id) {
$.ajax({
type:"get",
url:"<%=basePath%>customer/edit.action",
data:{"id":id},
success:function(data) {
$("#edit_cust_id").val(data.cust_id);
$("#edit_customerName").val(data.cust_name);
$("#edit_customerFrom").val(data.cust_source)
$("#edit_custIndustry").val(data.cust_industry)
$("#edit_custLevel").val(data.cust_level)
$("#edit_linkMan").val(data.cust_linkman);
$("#edit_phone").val(data.cust_phone);
$("#edit_mobile").val(data.cust_mobile);
$("#edit_zipcode").val(data.cust_zipcode);
$("#edit_address").val(data.cust_address);
}
});
}
Controll:
@RequestMapping("edit")
@ResponseBody
public Customer getCustomerById(Integer id){
Customer customer = customerService.getCustomerById(id);
return customer;
}