浪人情歌

流浪的人,流浪的心

首页 新随笔 联系 订阅 管理
/******************************************/
/***** 从微软网站上提取的Ajax客户端请求类*****/
/******************************************/
function Req() {}
Req.makeRequest 
= function(p_url,p_busyReq,p_progId,p_successCallBack,p_errorCallBack,p_pass) {
    if (p_busyReq) return;
    
var req = Req.getRequest();
    
if (req != null{
        p_busyReq 
= true;
        Req.showProgress(p_progId);
        req.onreadystatechange 
= function() {
            
if (req.readyState == 4{
                p_busyReq 
= false;
                window.clearTimeout(toId);
                
if (req.status == 200{
                    p_successCallBack(req,p_pass);
                }
 else {
                    p_errorCallBack(req,p_pass);
                }

            }

        }

        req.open(
"GET", p_url, true);
        req.send(
null);
        
var toId = window.setTimeout( function() {if (p_busyReq) req.abort();}, Req.timeout );
    }

}

Req.getRequest 
= function() {
    
var xmlHttp;
    
try { xmlHttp = new ActiveXObject("MSXML2.XMLHTTP"); return xmlHttp; } catch (e) {}
    
try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); return xmlHttp; } catch (e) {}
    
try { xmlHttp = new XMLHttpRequest(); return xmlHttp; } catch(e) {}
    
return null;
}

Req.showProgress 
= function(p_id) {
    
if (p_id != "") document.getElementById(p_id).innerHTML = Req.getProgressHtml();
}

Req.getProgressHtml 
= function() {
    
return "<p><img src='waiting.gif' align='middle' width='16' height='16' />Waiting........</p>";
}

Req.getErrorHtml 
= function(p_req) {
    
    return "<p>" + "(" + p_req.status + "" + p_req.statusText + "</p>"
}

Req.timeout 
= 5000;


Req.makeRequest = function(p_url,p_busyReq,p_progId,p_successCallBack,p_errorCallBack,p_pass) 中
p_url为需要请求的连接。
p_busyReq 表示是否正在请求数据
p_progId表示显示请求过程中正在等待内容的标签的ID 比如 <DIV id="div1"></DIV>  p_progId就等于div1
p_successCallBack表示成功得到数据后回调的函数
p_errorCallBack表示没有成功得到数据后回调的函数
p_pass表示请求时带来的参数,返回给回调后的函数中。

posted on 2006-06-23 16:12  郝晶  阅读(178)  评论(0)    收藏  举报