<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        Ajax 核心框架函數及例子

        來源:懂視網 責編:小采 時間:2020-11-27 22:52:30
        文檔

        Ajax 核心框架函數及例子

        Ajax 核心框架函數及例子:核心ajax(options)函數中,包含了建立xmlhttprequest,提取數據,判斷是否回復成功等,基本滿足了日常需求。 代碼如下:// A generic function for performming AJAX requests // It takes one argument, which is a
        推薦度:
        導讀Ajax 核心框架函數及例子:核心ajax(options)函數中,包含了建立xmlhttprequest,提取數據,判斷是否回復成功等,基本滿足了日常需求。 代碼如下:// A generic function for performming AJAX requests // It takes one argument, which is a

        核心ajax(options)函數中,包含了建立xmlhttprequest,提取數據,判斷是否回復成功等,基本滿足了日常需求。
        代碼如下:

        // A generic function for performming AJAX requests
        // It takes one argument, which is an object that contains a set of options
        // All of which are outline in the comments, below
        function ajax( options ) {
        // Load the options object with defaults, if no
        // values were provided by the user
        options = {
        // The type of HTTP Request
        type: options.type || "POST",
        // The URL the request will be made to
        url: options.url || "",
        // How long to wait before considering the request to be a timeout
        timeout: options.timeout || 5000,
        // Functions to call when the request fails, succeeds,
        // or completes (either fail or succeed)
        onComplete: options.onComplete || function(){},
        onError: options.onError || function(){},
        onSuccess: options.onSuccess || function(){},
        // The data type that'll be returned from the server
        // the default is simply to determine what data was returned from the
        // and act accordingly.
        data: options.data || ""
        };
        // Create the request object
        var xml = new XMLHttpRequest();
        // Open the asynchronous POST request
        //xml.open("GET", "/some/url.cgi", true);
        xml.open("GET",options.url, true);
        // We're going to wait for a request for 5 seconds, before giving up
        var timeoutLength = 5000;
        // Keep track of when the request has been succesfully completed
        var requestDone = false;
        // Initalize a callback which will fire 5 seconds from now, cancelling
        // the request (if it has not already occurred).
        setTimeout(function(){
        requestDone = true;
        }, timeoutLength);
        // Watch for when the state of the document gets updated
        xml.onreadystatechange = function(){
        // Wait until the data is fully loaded,
        // and make sure that the request hasn't already timed out
        if ( xml.readyState == 4 && !requestDone ) {
        // Check to see if the request was successful
        if ( httpSuccess( xml ) ) {
        // Execute the success callback with the data returned from the server
        options.onSuccess( httpData( xml, options.type ) );
        // Otherwise, an error occurred, so execute the error callback
        } else {
        options.onError();
        }
        // Call the completion callback
        options.onComplete();
        // Clean up after ourselves, to avoid memory leaks
        xml = null;
        }
        };
        // Establish the connection to the server
        xml.send();
        // Determine the success of the HTTP response
        function httpSuccess(r) {
        try {
        // If no server status is provided, and we're actually
        // requesting a local file, then it was successful
        return !r.status && location.protocol == "file:" ||
        // Any status in the 200 range is good
        ( r.status >= 200 && r.status < 300 ) ||
        // Successful if the document has not been modified
        r.status == 304 ||
        // Safari returns an empty status if the file has not been modified
        navigator.userAgent.indexOf("Safari") >= 0 && typeof r.status == "undefined";
        } catch(e){}
        // If checking the status failed, then assume that the request failed too
        return false;
        }
        // Extract the correct data from the HTTP response
        function httpData(r,type) {
        // Get the content-type header
        var ct = r.getResponseHeader("content-type");
        // If no default type was provided, determine if some
        // form of XML was returned from the server
        var data = !type && ct && ct.indexOf("xml") >= 0;
        // Get the XML Document object if XML was returned from
        // the server, otherwise return the text contents returned by the server
        data = type == "xml" || data ? r.responseXML : r.responseText;
        // If the specified type is "script", execute the returned text
        // response as if it was JavaScript
        if ( type == "script" )
        eval.call( window, data );
        // Return the response data (either an XML Document or a text string)
        return data;
        }
        }

        在同等目錄中,我們可以建立一個rss.xml文件,用這個函數來訪問。
        rss.xml如下:
        代碼如下:

        <titles>
        <title>
        緣份
        </title>
        <title>
        月亮
        </title>
        <title>
        緣份月亮
        </title>
        </titles>

        再建立一個html文檔,調用它,就能看到rss.xml中的內容就能被訪問到。
        整體看看,其實真的比較簡潔和簡單。不僅是能訪問xml格式文件,html,.js格式的文件都可以調用的;
        這些都可以在本地建立對應的文件,進行調用,都可以實現。

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        Ajax 核心框架函數及例子

        Ajax 核心框架函數及例子:核心ajax(options)函數中,包含了建立xmlhttprequest,提取數據,判斷是否回復成功等,基本滿足了日常需求。 代碼如下:// A generic function for performming AJAX requests // It takes one argument, which is a
        推薦度:
        標簽: aj 實例 函數
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 久久久久亚洲AV无码专区首| 亚洲精品免费网站| 亚洲欧美不卡高清在线| 日本亚洲欧洲免费天堂午夜看片女人员| 拍拍拍又黄又爽无挡视频免费| 亚洲av综合avav中文| 亚洲一级片免费看| 国产91久久久久久久免费| 亚洲一区二区三区在线 | 粉色视频免费入口| 好吊妞视频免费视频| 亚洲沟沟美女亚洲沟沟| 久久99热精品免费观看动漫| 亚洲AV中文无码乱人伦下载| 在线观看视频免费完整版| 亚洲经典在线观看| 亚洲国产成人精品女人久久久| 国产亚洲综合久久| 亚洲最大中文字幕| 无码人妻久久一区二区三区免费丨| 一区二区三区免费视频播放器 | 亚洲中久无码不卡永久在线观看| 国产精品亚洲综合天堂夜夜| 亚洲好看的理论片电影| 日本免费一区二区三区| 亚洲免费二区三区| 日本大片在线看黄a∨免费| 国产午夜亚洲精品不卡免下载 | 亚洲午夜电影在线观看| 国产成人亚洲综合| 午夜寂寞在线一级观看免费| 美女被免费网站在线视频免费 | 国产男女猛烈无遮挡免费视频 | 亚洲精品国产美女久久久| 成人性生交大片免费看好| 亚洲大成色www永久网站| 日韩免费一区二区三区在线播放| 亚洲欧美成人一区二区三区| 亚洲日产2021三区| 亚洲AV电影院在线观看| 亚洲人成色7777在线观看|