方式一: $.post(url, data , function(ms) {} );
其中data 用的是类似: data = {'vallemp.seiId', eid};
方式二:
$.ajax ( {
url : 'mainServlet.html?packgname=service&clsname=DBService&method=service&operate=decideDBType&ds=tsdBilling',
datatpe:'', //html, xml,
data:"hkHotelCd="+hkHotelCd+"&hkHotelRoomKind="+hkHotelRoomKind,
cache:false,//如果值变化可能性比较大 一定要将缓存设成false
timeout: 1000,
error: function(){alert('error');$('#LoadingStatus').hide(2000);}, //错误处理,隐藏进度条
async: false ,//同步方式(同步) 如果要采用异步的方式 请设置为true
success:function(xml){
alert(xml);
$(xml).find('row').each(function(){
arr.push($(this).attr("area"));
});
}
}) ;
方式二 后台:
/**
* AJAX 根据条件调用接口判断配额是否满足需求
*/
public String ajaxCheckHotelQutota() {
String hkHotelCd = ServletActionContext.getRequest().getParameter("hkHotelCd");
String hkHotelRoomKind = ServletActionContext.getRequest().getParameter("hkHotelRoomKind");
String hkHotelPriceKind = ServletActionContext.getRequest().getParameter("hkHotelPriceKind");
String startDate = ServletActionContext.getRequest().getParameter("startDate");
String endDate = ServletActionContext.getRequest().getParameter("endDate");
int quantity = Integer.parseInt(ServletActionContext.getRequest().getParameter("quantity"));
//调用接口验证时间段 中旅该房型 是否满足配额需求
boolean check = false;
try {
check = hkService.checkHotelQuota(hkHotelCd, hkHotelRoomKind, hkHotelPriceKind, format.parse(startDate), format.parse(endDate), quantity);
} catch (ParseException e) {
log.error("日期转换格式错误(startDate, endDate)!",e);
}
Writer out = null;
HttpServletResponse httpServletResponse = ServletActionContext.getResponse();
httpServletResponse.setCharacterEncoding("UTF-8");
try {
out = httpServletResponse.getWriter();
out.write(String.valueOf(check));
out.flush();
}catch(Exception ee) {
log.error("通过ServletActionContext获取response,writer出错!",ee);
}finally {
if(null!=out) {
try {
out.close();
} catch (IOException e) {
log.error("writer close出错!",e);
}
}
}
return null;
}
方式三:json
$.ajax({
type: "get",//使用get方法访问后台
dataType: "json",//返回json格式的数据
url: "BackHandler.ashx",//要访问的后台地址
data: "pageIndex=" + pageIndex,//要发送的数据
complete :function(){$("#load").hide();},//AJAX请求完成时隐藏loading提示
success: function(msg){//msg为返回的数据,在这里做数据绑定
var data = msg.table;
$.each(data, function(i, n){
var row = $("#template").clone();
row.find("#OrderID").text(n.订单ID);
});
AJAX提交FORM表单: (如果异步提交参数太多,可以采用 $("#doOrderForm").serialize() 方式提交)
$.ajax({
url:"ajaxOccupySale.shtml",
type:"post",
data:$("#doOrderForm").serialize(),
async: false,
success: function(xml){
alert(xml);
}
});