码迷,mamicode.com
首页 > 编程语言 > 详细

javascript原型方法

时间:2014-11-18 23:27:30      阅读:363      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   java   

 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 }
bubuko.com,布布扣
 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 }
View Code

 

javascript原型方法

标签:style   blog   http   io   ar   color   os   sp   java   

原文地址:http://www.cnblogs.com/zxiong/p/4106488.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!