/*
 * AJAX请求类
 */
function AjaxRequest(url,data,callBack,error,async){
	this.type = "post";//数据传递方式(get或post)。
	this.url = url;
	this.async = typeof(async)=="undefined" ? true : async;//是否同步，false同步 true异步
	this.data = data;//传递数据的参数字符串，只适合post方式
	this.dataType = "json";//期待数据返回的数据格式(例如 "xml", "html", "script",或 "json")
	this.ifModified = false;//当最后一次请求的相应有变化是才成功返回，默认值是false
	this.timeout = 0;//设置时间延迟请求的时间。可以参考$.ajaxTimeout
	this.global = true;//是否为当前请求触发ajax全局事件，默认为true
	this.error = typeof error == "function" ? error : function(data , status , e){alert("AjaxRequest error:"+e.message);};//当请求失败时触发的函数。
	this.success = successFunc;//当请求成功时触发函数
	this.complete = null;//当请求完成后出发函数
	
	this.data.submitType = "ajax";
	
	this.begin = function(){
		
		var params = {
			type : this.type,
			url  : this.url,
			async : this.async,
			data : this.data,
			dataType : this.dataType,
			ifModified : this.ifModified,
			timeout : this.timeout,
			global : this.global,
			error : this.error,
			success : this.success,
			complete : this.complete
		};
		
		$.ajax(params);
	}
	
	function checkError(data){
		if(data && data.error){
			
			new ErrorPrompt(data.error);
			
			return true;
		}
		return false;
	}
	
	/*function errorFunc(e){
		alert("发生错误:"+e.message);
	}*/
	
	function successFunc(data , status){
		//try{
			//a.a;
			if(!checkError(data)){
				if(!checkLogin(data)) return;
				callBack(data , status);
			}
			
		//}catch(e){
			//errorFunc(e);
		//}
	}
}

function ErrorPrompt(message){
	alert(message);
}
