<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
        主站蜘蛛池模板: 免费无码午夜福利片69| 在线播放亚洲第一字幕| 国产成人精品久久亚洲| 亚洲国产无线乱码在线观看 | 37pao成人国产永久免费视频| 成人免费在线观看网站| 亚洲成年人啊啊aa在线观看| 亚洲精品午夜无码电影网| 亚洲a级成人片在线观看| h片在线播放免费高清 | 亚洲人成图片小说网站| 一本到卡二卡三卡免费高| 思思re热免费精品视频66| 亚洲精品岛国片在线观看| 国产精品免费视频观看拍拍| 最新亚洲成av人免费看| 亚洲另类无码一区二区三区| 国产精品免费无遮挡无码永久视频 | 麻豆69堂免费视频| 91成人免费观看网站| 中文字幕精品亚洲无线码一区| 91在线亚洲综合在线| 日韩一品在线播放视频一品免费| 无码乱人伦一区二区亚洲| 男人和女人高潮免费网站| 久久精品网站免费观看| 亚洲AV天天做在线观看| 无限动漫网在线观看免费| 国产AV无码专区亚洲AV蜜芽| 男女免费观看在线爽爽爽视频 | 狠狠综合久久综合88亚洲| 亚洲AV无码资源在线观看| 亚洲第一成人影院| 青青青亚洲精品国产| 亚洲国产精品无码久久久秋霞2| 91香焦国产线观看看免费| 色婷婷六月亚洲综合香蕉| 久久精品国产亚洲网站| 香蕉免费一级视频在线观看| 亚洲av麻豆aⅴ无码电影| 久久国产精品国产自线拍免费|