大学哩

 
  • 游客
收藏 | 举报 2017-09-30 09:17   关注:32656   回答:1

java认证:一个比较方便通用的自定义Ajax函数是什么?

已关闭 悬赏分:0
举报 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];
0条 [查看全部]  相关评论