举报
2017-09-30 10:29
function Ajax()
{
var len=arguments.length;
var type,url,postdata,fn;
if(len2)
{
var args=arguments[2];
if(typeof(args)=="string")
{
postdata=args;
}
}
var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
xhr.open(type,url,true);
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
fn = arguments[len-1];
xhr.onreadystatechange = function (){
if(xhr.readyState==4)
{
if(xhr.status==200)
{
if(typeof(fn)=="function")
fn(xhr.responseText);
}
else
{
alert("你所请求的页面有异常");
}
}
};
xhr.send(postdata);
}
function Test()
{
Ajax("get","/WebRoot/servlet/TestAjax");
Ajax("get","/WebRoot/servlet/TestAjax",function (date){
alert("Get Date:\n"+date);
});
Ajax("post","/WebRoot/servlet/TestAjax");
Ajax("post","/WebRoot/servlet/TestAjax",function (date){
alert("Post Date:\n"+date);
});
Ajax("post","/WebRoot/servlet/TestAjax","username=jonllen&pwd=123456",function (date){
alert("Post Date:\n"+date);
});
}
function Ajax()
{
var len=arguments.length;
var type,url,postdata,fn;
if(len2)
{
var args=arguments[2];
if(typeof(args)=="string")
{
postdata=args;
}
}
var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
xhr.open(type,url,true);
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
fn = arguments[len-1];
|