正则处理url 封装ajax
function getUrlPara(paraName){
???????? var sUrl? =? location.href;
???????? var sReg? =? "(?:\\?|&){1}"+paraName+"=([^&]*)"
???????? var re=new RegExp(sReg,"gi");
???????? re.exec(sUrl);
???????? return RegExp.$1;
??? }
??? document.domain = "kunlun2000.com";
??? getPra();
?
?
??? function AJAXRequest() {
?var xmlObj = false;
?var CBfunc,ObjSelf;
?ObjSelf=this;
?if(window.ActiveXObject){
??????? ?xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
??? ?}else if(window.ActiveXObject){
??????? ?xmlObj = new ActiveXObject("Msxml2.XMLHTTP.4.0");
??? ?}else if(window.ActiveXObject){
??????? ?xmlObj = new ActiveXObject("Msxml2.XMLHTTP");
??? ?}else if(window.XMLHttpRequest){
??????? ?xmlObj = new XMLHttpRequest();
??? ?}
?if (!xmlObj) return false;
?if(arguments[0]) this.url=arguments[0]; else this.url="";
?if(arguments[1]) this.callback=arguments[1]; else this.callback=function(obj){return};
?if(arguments[2]) this.content=arguments[2]; else this.content="";
?if(arguments[3]) this.method=arguments[3]; else this.method="POST";
?if(arguments[4]) this.async=arguments[4]; else this.async=true;
?this.send=function() {
??var purl,pcbf,pc,pm,pa;
??if(arguments[0]) purl=arguments[0]; else purl=this.url;
??if(arguments[1]) pc=arguments[1]; else pc=this.content;
??if(arguments[2]) pcbf=arguments[2]; else pcbf=this.callback;
??if(arguments[3]) pm=arguments[3]; else pm=this.method;
??if(arguments[4]) pa=arguments[4]; else pa=this.async;
??if(!pm||!purl||!pa) return false;
??xmlObj.open (pm, purl, pa);
??if(pm=="POST") xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
??xmlObj.onreadystatechange=function() {
???if(xmlObj.readyState==4) {
????if(xmlObj.status==200) {
?????pcbf(xmlObj);
????}
????else {
?????pcbf(null);
????}
???}
??}
??if(pm=="POST")
???xmlObj.send(pc);
??else
???xmlObj.send("");
?}
?this.get=function() {
??var purl,pcbf;
??if(arguments[0]) purl=arguments[0]; else purl=this.url;
??if(arguments[1]) pcbf=arguments[1]; else pcbf=this.callback;
??if(!purl&&!pcbf) return false;
??this.send(purl,"",pcbf,"GET",true);
?}
?this.post=function() {
??var fo,pcbf,purl,pc,pm;
??if(arguments[0]) fo=arguments[0]; else return false;
??if(arguments[1]) pcbf=arguments[1]; else pcbf=this.callback;
??if(arguments[2])
???purl=arguments[2];
??else if(fo.action)
???purl=fo.action;
??else
???purl=this.url;
??if(arguments[3])
???pm=arguments[3];
??else if(fo.method)
???pm=fo.method.toLowerCase();
??else
???pm="post";
??if(!pcbf&&!purl) return false;
??pc=this.formToStr(fo);
??if(!pc) return false;
??if(pm) {
???if(pm=="post")
????this.send(purl,pc,pcbf,"POST",true);
???else
????if(purl.indexOf("?")>0)
?????this.send(purl+"&"+pc,"",pcbf,"GET",true);
????else
?????this.send(purl+"?"+pc,"",pcbf,"GET",true);
??}
??else
???this.send(purl,pc,pcbf,"POST",true);
?}
?this.formToStr=function(fc) {
??var i,query_string="",and="";
??for(i=0;i<fc.length;i++) {
???e=fc[i];
???if (e.name!='') {
????if (e.type=='select-one') {
?????elementvalue=e.options[e.selectedIndex].value;
????}
????else if (e.type=='checkbox' || e.type=='radio') {
?????if (e.checked==false) {
??????continue;
?????}
?????elementvalue=e.value;
????}
????else {
?????elementvalue=e.value;
????}
????elementvalue=encodeURIComponent(element_value);
????query_string+=and+e.name+'='+element_value;
????and="&";
???}
??}
??return query_string;
?}
}
function gsNewsList(pageNO) {
?var ajax=new AJAXRequest;
?ajax.get(
??"http://www.kunlun2000.com:8180/kunlun/gsnewslist.jsp?pageNO="+pageNO,
??function(obj) {
???document.getElementById("gsxwNewsList").innerHTML=obj.responseText;
??}
?);
}
function getPra()
{
??? var pageNO=getUrlPara("pages");
??? gsNewsList(pageNO);
}
?
?
学习函数
1 楼 thunderbow 2010-07-14 if (this.element.value) {