小巧的ajax

 

var Ajax=function(option){
	var request;
	var CreateRquest=function(){
		var httpRequest;
		try{
			httpRequest=new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e1){
				httpRequest=new XMLHttpRequest();
			}
		}
		return httpRequest;
	}
	
	var SendRequest=function(){
		request=CreateRquest();
		request.open("post",option.Url,true);
		request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		request.onreadystatechange=ResponseRequest;
		request.send(option.Param);
	}
	var ResponseRequest=function(){
		if(request.readystate==4){
			if(request.status==200){
				option.Success(request);
			}else{
				option.Failure(request);
			}
		}
	}
  SendRequest();
}

function ajaxSubmit(){
	var option={
		Url:"index.php",
		Param:"text=aaaaa",
		Success:function(request){
			alert(request.responseText);
		},
		Failure:function(request){
			alert(false);
		}
  };
  new Ajax(option);
}

你可能感兴趣的:(小巧的ajax)