问题一:Ajax传递整个表单数据:
function createCustomer() {
$.post("${pageContext.request.contextPath}/list/add.do",
$("#new_customer_form").serialize(),function(data){
if(data =="OK"){
alert("客户创建成功!");
window.location.reload();
}else{
alert("客户创建失败!");
window.location.reload();
}
});
}
其中,new_customer_form为表单的ID,serialize()数据序列化,function(data)中的data即为后台返回在值;
问题二:Ajax传递某个数据:
function editCustomer(id) {
$.ajax({
type:"get",
url:"${pageContext.request.contextPath}/list/edit.do",
data:{"id":id},
success:function(data) {
$("#edit_cust_id").val(data.cust_id);
$("#cust_name").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);
}
});
}
其中的id即为传递的数据;
问题三:利用js进行数据回显,见上面的js代码,其中的 $("#edit_cust_id")即为单个输入的ID,val(data.cust_id);为要在该输入框中显示的内容信息。