//可以使用传统的ajax方式来操作,也可以使用面对对象的思想在对ajax进行操作
/*
** 使用基础的ajax
**
**
*/
// 前台jsp代码
**************************test.jsp部分代码*****************************
(function(){(“#submit_btn”).click(function(){
var cphm = (“#cphm”).val();(“#frm_carnum”).serialize();
$.ajax({
url : “parkReport.do?cphm=” + cphm,
type : “post”,
async : true, //默认为true 异步
cache : false,
error : function() {
alert(‘error’);
},
success : function(data) {
alert(“cphm : “+data.cphm+”, userPhoneNumber : “+data.userPhoneNumber);
}
});
})
});
—————————————–
//相应的servel.java
JSONObject json = new JSONObject();
json.put(“cphm”, cphm);
json.put(“userPhoneNumber”, userPhoneNumber);
json.put(“resultMsg”, resultMsg );
out.println(
” {\”cphm\”:\”” + cphm + “\”,”
+ “\”userPhoneNumber\”:\”” + userPhoneNumber + “\”,”
+ “\”resultMsg\”:\”” + resultMsg + “\”}”);
//这样就可以传入相依的值了
————————————–
//第二种 可以是用封装的js,然后通过面向对象的思想来 封装 ajax
$(function(){
$("#confirm").click(function() {
var cphm = $("#cphm").val();
var message = $("#liuyan").val();
var op = new AjaxOp();
op.dataType = "json";
op.url = "parkReport.do?cphm="+cphm;
op.callback=function(data){
var resultMsg = data.resultMsg;
if(0 == data.userPhoneNumber.length){
window.wxc.xcConfirm("该车主未登记,找不到号码",window.wxc.xcConfirm.typeEnum.confirm);
}
if(0 != resultMsg.length){
// window.wxc.xcConfirm(“该车主留有一条报备消息,是否查看”,window.wxc.xcConfirm.typeEnum.confirm);
// window.wxc.xcConfirm(“该车主留有一条报备消息,是否查看”+resultMsg+”\n 详情请回微信窗口页面”,window.wxc.xcConfirm.typeEnum.confirm);
window.confirm(“该车主留有一条报备消息,是否查看”);
alert(“【汪汪移车提示】:\n”+resultMsg+”\n 详情请回微信窗口页面”);
}else{
/目前不做任何处理/
}
window.location.href = “tel:”+data.userPhoneNumber;
};
op.onError = function(){
alert(“error”);
}
op.execute();
});