javascript原型方法
1 function createXMLHttp() { 2 if(window.XMLHttpRequest){ 3 return new XMLHttpRequest(); 4 } else if(window.ActiveXObject){ 5 return new ActiveXObject("Microsoft.XMLHTTP"); 6 7 var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP']; 8 for (var i = 0; i < versions.length; i++) { 9 try { 10 request = new ActiveXObject(versions[i]); 11 if (request) { 12 return request; 13 } 14 } catch (e) { } 15 } 16 17 } 18 throw new Error("XMLHttp object could be created."); 19 }
1 function _sendRequest(url,func,isxml,postdata) 2 { 3 var xhr=createXMLHttp(); 4 if(!postdata)postdata=null; 5 xhr.open(postdata?"POST":"GET",url,true); 6 if (postdata) 7 { 8 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 9 } 10 if(func){ 11 xhr.onreadystatechange=function(){ 12 if(xhr.readyState==4){ 13 func(isxml&&xhr.responseXML?xhr.responseXML:xhr.responseText) 14 } 15 } 16 } 17 if (postdata === true) 18 { 19 postdata = ''; 20 } 21 xhr.send(postdata) 22 }
1 function showadminlogpage(dataSource) { 2 3 _sendRequest(dataSource, function (responseText) { 4 var varlist; 5 6 try { 7 varlist = eval("(" + responseText + ")"); 8 } 9 catch (e) { 10 varlist = new Array(); 11 } 12 13 var html = '<table border="1" width="100%">'; 14 15 var adminloglist = varlist.adminloglist; 16 var pagenumbers = varlist.pagenumbers; 17 18 var pagenumbers_buttom = 'adminlog_pagenumbers'; 19 var page_owner = 'adminlogpage_owner'; 20 21 for (var i = 0; i < adminloglist.length; i++) { 22 html += ' <tr>' 23 html += ' <td>Visitid:' + adminloglist[i].Visitid + '</td>'; 24 html += ' <td>Adminname:' + adminloglist[i].Adminname + '</td>'; 25 html += ' <td>Ip:' + adminloglist[i].Ip + '</td>'; 26 html += ' <td>Others:' + adminloglist[i].Others + '</td>'; 27 html += ' <td>Actiontype:' + adminloglist[i].Actiontype + '</td>'; 28 html += ' <td>Addtime:' + adminloglist[i].Addtime + '</td>'; 29 html += ' </tr>' 30 } 31 html += '</table>' 32 document.getElementById(pagenumbers_buttom).innerHTML = pagenumbers; 33 document.getElementById(page_owner).innerHTML = html; 34 }, false); 35 }