軟件藝術(shù)思考者  
          混沌,彷徨,立志,蓄勢...
          公告
          日歷
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導(dǎo)航

          隨筆分類(86)

          隨筆檔案(85)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

           

          樹青兄寫的一個ajax類。
          var http_request = false;
          function send_request(method,url,formName,responseType,callback) {
          ?http_request = false;
          ?var content =""
          ?if(forName != null)content = getFormAsString(formName);
          ??
          ?if(window.XMLHttpRequest) {
          ??http_request = new XMLHttpRequest();
          ??if (http_request.overrideMimeType) {
          ???http_request.overrideMimeType("text/xml");
          ??}
          ?}
          ?else if (window.ActiveXObject) {
          ??try {
          ???http_request = new ActiveXObject("Msxml2.XMLHTTP");
          ??} catch (e) {
          ???try {
          ????http_request = new ActiveXObject("Microsoft.XMLHTTP");
          ???} catch (e) {}
          ??}
          ?}
          ?if (!http_request) {
          ??window.alert("不能創(chuàng)建XMLHttpRequest對象實例.");
          ??return false;
          ?}
          ?if(responseType.toLowerCase()=="text") {
          ??http_request.onreadystatechange = callback;
          ?}
          ?else if(responseType.toLowerCase()=="xml") {
          ??http_request.onreadystatechange = callback;
          ?}
          ?else {
          ??window.alert("響應(yīng)類別參數(shù)錯誤。");
          ??return false;
          ?}
          ?if(method.toLowerCase()=="get") {
          ??http_request.open(method, url, true);
          ?}
          ?else if(method.toLowerCase()=="post") {
          ??http_request.open(method, url, true);
          ??http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");??
          ?}
          ?else {
          ??window.alert("http請求類別參數(shù)錯誤。");
          ??return false;
          ?}??
          ?if(window.ActiveXObject) http_request.setRequestHeader("If-Modified-Since", "0");
          ?http_request.send(content);
          }

          function getFormAsString(formName){

          returnString ="";

          formElements=document.forms[formName].elements;

          for(var i=formElements.length-1;i>=0; --i ){

          returnString+="&"

          +escape(formElements[i].name)+"="

          +escape(formElements[i].value);

          }

          }

          posted on 2006-11-28 15:03 智者無疆 閱讀(305) 評論(4)  編輯  收藏 所屬分類: Client teachnolgy research
          評論:
          • # re: ajax study (1)  self Posted @ 2006-11-28 15:14
            用法:
            send_request("POST","../index.htm","form1","text",changprocess)  回復(fù)  更多評論   

          • # re: ajax study (1)  self Posted @ 2006-12-11 16:19
            改進后的。
            var http_request = false;

            function send_request(method,url,formName,responseType,callback) {
            http_request = false;
            var content =""
            content = getFormAsString(formName);

            if(window.XMLHttpRequest) {
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
            http_request.overrideMimeType("text/xml");
            }
            }
            else if (window.ActiveXObject) {
            try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
            try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
            }
            }
            if (!http_request) {
            window.alert("不能創(chuàng)建XMLHttpRequest對象實例.");
            return false;
            }
            if(responseType.toLowerCase()=="text") {
            http_request.onreadystatechange = callback;
            }
            else if(responseType.toLowerCase()=="xml") {
            http_request.onreadystatechange = callback;
            }
            else {
            window.alert("響應(yīng)類別參數(shù)錯誤。");
            return false;
            }
            if(method.toLowerCase()=="get") {
            http_request.open(method, url, true);
            }
            else if(method.toLowerCase()=="post") {
            http_request.open(method, url, true);
            http_request.setRequestHeader('Content-Type','text/xml; charset=utf-8');
            }
            else {
            window.alert("http請求類別參數(shù)錯誤。");
            return false;
            }
            if(window.ActiveXObject) http_request.setRequestHeader("If-Modified-Since", "0");
            http_request.send(content);
            }

            function getFormAsString(formName){

            returnString ="";

            formElements=document.forms[formName].elements;

            for(var i=formElements.length-1;i>=0; --i ){

            returnString+="&"

            +escape(formElements[i].name)+"="

            +escape(formElements[i].value);

            }
            return returnString;
            }   回復(fù)  更多評論   

          • # re: ajax study (1)  self Posted @ 2006-12-11 16:20
            一個好東西
            // mozXPath [http://km0ti0n.blunted.co.uk/mozxpath/] km0ti0n@gmail.com
            // Code licensed under Creative Commons Attribution-ShareAlike License
            // http://creativecommons.org/licenses/by-sa/2.5/
            if( document.implementation.hasFeature("XPath", "3.0") )
            {
            XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
            {
            if( !xNode ) { xNode = this; }

            var oNSResolver = this.createNSResolver(this.documentElement)
            var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
            var aResult = [];
            for( var i = 0; i < aItems.snapshotLength; i++)
            {
            aResult[i] = aItems.snapshotItem(i);
            }

            return aResult;
            }
            XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
            {
            if( !xNode ) { xNode = this; }

            var xItems = this.selectNodes(cXPathString, xNode);
            if( xItems.length > 0 )
            {
            return xItems[0];
            }
            else
            {
            return null;
            }
            }

            Element.prototype.selectNodes = function(cXPathString)
            {
            if(this.ownerDocument.selectNodes)
            {
            return this.ownerDocument.selectNodes(cXPathString, this);
            }
            else{throw "For XML Elements Only";}
            }

            Element.prototype.selectSingleNode = function(cXPathString)
            {
            if(this.ownerDocument.selectSingleNode)
            {
            return this.ownerDocument.selectSingleNode(cXPathString, this);
            }
            else{throw "For XML Elements Only";}
            }

            }  回復(fù)  更多評論   

          • # re: ajax study (1)  self Posted @ 2006-12-11 16:20
            一個好東西
            // mozXPath [http://km0ti0n.blunted.co.uk/mozxpath/] km0ti0n@gmail.com
            // Code licensed under Creative Commons Attribution-ShareAlike License
            // http://creativecommons.org/licenses/by-sa/2.5/
            if( document.implementation.hasFeature("XPath", "3.0") )
            {
            XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
            {
            if( !xNode ) { xNode = this; }

            var oNSResolver = this.createNSResolver(this.documentElement)
            var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
            var aResult = [];
            for( var i = 0; i < aItems.snapshotLength; i++)
            {
            aResult[i] = aItems.snapshotItem(i);
            }

            return aResult;
            }
            XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
            {
            if( !xNode ) { xNode = this; }

            var xItems = this.selectNodes(cXPathString, xNode);
            if( xItems.length > 0 )
            {
            return xItems[0];
            }
            else
            {
            return null;
            }
            }

            Element.prototype.selectNodes = function(cXPathString)
            {
            if(this.ownerDocument.selectNodes)
            {
            return this.ownerDocument.selectNodes(cXPathString, this);
            }
            else{throw "For XML Elements Only";}
            }

            Element.prototype.selectSingleNode = function(cXPathString)
            {
            if(this.ownerDocument.selectSingleNode)
            {
            return this.ownerDocument.selectSingleNode(cXPathString, this);
            }
            else{throw "For XML Elements Only";}
            }

            }  回復(fù)  更多評論   

           
          Copyright © 智者無疆 Powered by: 博客園 模板提供:滬江博客


             觀音菩薩贊

          主站蜘蛛池模板: 宜丰县| 鞍山市| 柳林县| 措美县| 武邑县| 杭锦旗| 大名县| 出国| 高碑店市| 石家庄市| 韶山市| 招远市| 呼图壁县| 莒南县| 阿克陶县| 崇义县| 临夏县| 雅安市| 伊宁市| 丹江口市| 奇台县| 黔西| 郓城县| 剑河县| 聂拉木县| 石泉县| 天镇县| 通河县| 南阳市| 江永县| 谷城县| 郑州市| 东海县| 永春县| 孝义市| 永寿县| 荣成市| 漠河县| 柯坪县| 哈密市| 沐川县|