aspx与ascx,ashx的用法总结(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 runat="server">
    <title>mytest</title>
    <script type="text/javascript">
        function $(s) { if (document.getElementById) { return eval('document.getElementById("' + s + '")'); } else { return eval('document.all.' + s); } }

function createXMLHTTP() {
            var xmlHttp = false;
            var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
                         "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
                         "Microsoft.XMLHTTP"];
            for (var i = 0; i < arrSignatures.length; i++) {
                try {
                    xmlHttp = new ActiveXObject(arrSignatures[i]);
                    return xmlHttp;
                }
                catch (oError) {
                    xmlHttp = false; //ignore
                }
            }
            // throw new Error("MSXML is not installed on your system.");
            if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
                xmlHttp = new XMLHttpRequest();
            }
            return xmlHttp;
        }

var xmlReq = createXMLHTTP();

// 发送ajax处理请求(这里简单验证旧密码的有效性)
        function validateOldPwd(oTxt) {
            var url = "/HandlerTest.ashx?action=modifyPwd&pwd=" + escape(oTxt.value); //.ashx文件
            xmlReq.open("get", url, true);
            xmlReq.setRequestHeader("If-Modified-Since", "0");
            xmlReq.onreadystatechange = callBack;
            xmlReq.send(url); // 发送文本
        }

function callBack() {
            if (xmlReq.readyState == 4) {
                if (xmlReq.status == 200) {
                    alert(xmlReq.responseText); // 接收文本
                }
                else if (xmlReq.status == 404) {
                    alert("Requested URL is not found.");
                } else if (xmlReq.status == 403) {
                    alert("Access denied.");
                } else
                    alert("status is " + xmlReq.status);
            }
        }

</script>

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

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