jquery Ajax 使用

方式一: $.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);
	}
});

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值