javascript Ajax 类实现代码(2)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Ajax类</title>
<script src="https://www.jb51.net/Ajax.js" src="https://www.jb51.net/Ajax.js"></script>

<style type="text/css"><!--
#Layer1 {
    position:absolute;
    left:670px;
    top:11px;
    width:15px;
    height:15px;
    z-index:10000;
    background-color:#FF0000;
    font-size:13;
    border:none;
    visibility:hidden;
}
--></style><style type="text/css" bogus="1">#Layer1 {
    position:absolute;
    left:670px;
    top:11px;
    width:15px;
    height:15px;
    z-index:10000;
    background-color:#FF0000;
    font-size:13;
    border:none;
    visibility:hidden;
}</style>
</head>

<body>
<div><img src="https://www.jb51.net/indicator_flower.gif" src="https://www.jb51.net/indicator_flower.gif" /></div>
<script type="text/javascript" language="javascript"><!--
function processRequest(http_request, _val, _loading_img){
    alert(http_request.responseXML.documentElement.xml);
    //alert(http_request.responseText);
    funHide(_loading_img);
}
// --></script>
<script type="text/javascript" language="javascript"><!--
var url = "http://www.w3schools.com/xml/simple.xml";
var data = "";

var ajax = new AjaxDO();

function btnAjax1(){
    //var ajax = new AjaxDO();
    //ajax.InitHttpRequest();
    ajax.abort();

    ajax.setLoadingImg(document.getElementById("Layer1"));
    ajax.setOnReadyStateChange(processRequest);
    ajax.Open("GET", url, true); //异步模式,程序继续执行
    ajax.Send("");
}

function btnAjax2(){
    //var ajax = new AjaxDO();
    //ajax.InitHttpRequest();
    ajax.abort();

    ajax.Open("GET", url, false); //非异步模式,程序等待
    ajax.Send("");
    alert(ajax.getResponseText("XML").documentElement.xml);
    alert(ajax.getResponseText("TEXT"));
}
// --></script>
<button>异步模式</button>
<button>非异步模式</button>
</body>
</html>


3、图片

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wfzwgs.html