Jquery Ajax 异步请求

Ajax异步请求Code示例:

$.ajax( {
				type : "post",
				// 查询所有区县
				url : 'transType.action',
				async : false,
				dataType : "json",
				data : {
					"sCity" : startCityCode,
					"aCity" : arrivedCityCode,
					"sArea" : startAreaCode,
					"aArea" : arrivedAreaCode
				},
				success : function(data) {
					if (data == null || data.length == 0) {
						cleanTransportTable();
					$("#errTxt").text("未查找到运输路线");
						return;
					} else {
						if (data.pricelist.length == 0) {
							cleanTransportTable();
					$("#errTxt").text("未查找到运输路线");
							return;
						}
						pricePlanBean = data.pricelist;
						count = data.count;
				isPilotCityOfA = data.isPilotCityOfA;
				hasAgentCityOfA = data.hasAgentCityOfA;
				orgCount = data.orgCount;
				//获取出发城市,到达城市,城市code,区域code
				departureCity = data.departureCity;
				destinationCity = data.destinationCity;
                                destinationArea=data.destinationArea;
			        departureArea=data.departureArea;		                            
				strVolume = _strVolume;
				weight = _weight;
				wrap = iswrap;
						
				if (data.orgCountOfCounty == 0) {
				alert("该线路尚未开通,运输方式只能选择汽运偏线");
						}		
				$("#createOrder").attr("disabled","");
				getTransport();//生成运输类型
  						
					}
				},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
				$("#errTxt").text("");
				$("#errTxt").text("网络繁忙,请稍后再试!");
				}
			});

transType.action部分代码:

Map<String, Object> map = new HashMap<String, Object>();
		map.put("pricelist", ppi);
		map.put("count", count);
		map.put("departureCity", sCity);
		map.put("destinationCity", aCity);
		map.put("departureArea", sArea); //出发城市区域code通过JSON传到订单
		map.put("destinationArea", aArea);//到达城市区域code通过JSON传到订单
		map.put("isPilotCityOfA", isPilot2); //到达城市是否为试点城市
		map.put("hasAgentCityOfA", hasAgent); //到达城市是否为落地配城市
		map.put("orgCount", orgCount); //到达城市德邦网点数
		map.put("orgCountOfCounty", orgCountOfCounty); //到达区县德邦网点数
		json = map;
		return "JSON";
		}
		return "JSON";

相关推荐