婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > Ajax 核心框架函數(shù)及例子

Ajax 核心框架函數(shù)及例子

熱門(mén)標(biāo)簽:如何用地圖標(biāo)注各分公司 辦理一個(gè)400電話多少錢(qián) 接聽(tīng)電話機(jī)器人哪有 莆田防封電銷(xiāo)卡價(jià)格 信貸電銷(xiāo)機(jī)器人有用嗎 蓄意標(biāo)記地圖標(biāo)注 電銷(xiāo)機(jī)器人適用范圍 廣西ai語(yǔ)音電銷(xiāo)機(jī)器人哪家好 察縣地圖標(biāo)注
核心ajax(options)函數(shù)中,包含了建立xmlhttprequest,提取數(shù)據(jù),判斷是否回復(fù)成功等,基本滿足了日常需求。
復(fù)制代碼 代碼如下:

// 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;
}
}

在同等目錄中,我們可以建立一個(gè)rss.xml文件,用這個(gè)函數(shù)來(lái)訪問(wèn)。
rss.xml如下:
復(fù)制代碼 代碼如下:

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

再建立一個(gè)html文檔,調(diào)用它,就能看到rss.xml中的內(nèi)容就能被訪問(wèn)到。
整體看看,其實(shí)真的比較簡(jiǎn)潔和簡(jiǎn)單。不僅是能訪問(wèn)xml格式文件,html,.js格式的文件都可以調(diào)用的;
這些都可以在本地建立對(duì)應(yīng)的文件,進(jìn)行調(diào)用,都可以實(shí)現(xiàn)。
您可能感興趣的文章:
  • Ajax核心XMLHTTP組件資料
  • Javascript級(jí)聯(lián)下拉菜單以及AJAX數(shù)據(jù)驗(yàn)證核心代碼
  • jquery ajax方式直接提交整個(gè)表單核心代碼
  • 解析ajax核心XMLHTTPRequest對(duì)象的創(chuàng)建與瀏覽器的兼容問(wèn)題
  • Ajax核心技術(shù)代碼分享
  • Ajax核心XMLHttpRequest總結(jié)
  • 簡(jiǎn)單談?wù)凙JAX核心對(duì)象

標(biāo)簽:益陽(yáng) 張掖 儋州 鷹潭 延邊 阿拉善盟 銅陵

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Ajax 核心框架函數(shù)及例子》,本文關(guān)鍵詞  Ajax,核心,框架,函數(shù),及,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Ajax 核心框架函數(shù)及例子》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于Ajax 核心框架函數(shù)及例子的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 嘉义市| 民勤县| 高雄县| 德化县| 准格尔旗| 广德县| 翁源县| 岱山县| 沧源| 长沙县| 清丰县| 咸阳市| 宜州市| 元朗区| 分宜县| 锦州市| 淄博市| 平定县| 海伦市| 建宁县| 宝山区| 甘泉县| 会理县| 贵南县| 金湖县| 遵化市| 合作市| 瑞金市| 金山区| 巩留县| 广饶县| 元氏县| 姜堰市| 云龙县| 东乡族自治县| 顺平县| 中宁县| 临澧县| 奉节县| 开平市| 红桥区|