jquery ajax的操作

//可以使用传统的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);
}
});
})
});

button

—————————————–

//相应的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();
});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值