中文字幕第五页-中文字幕第页-中文字幕韩国-中文字幕最新-国产尤物二区三区在线观看-国产尤物福利视频一区二区

Ajax核心框架函數有哪些-創新互聯

這篇文章主要為大家展示了“Ajax核心框架函數有哪些”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“Ajax核心框架函數有哪些”這篇文章吧。

10年積累的成都網站設計、成都網站建設經驗,可以快速應對客戶對網站的新想法和需求。提供各種問題對應的解決方案。讓選擇我們的客戶得到更好、更有力的網絡服務。我雖然不認識你,你也不認識我。但先網站設計制作后付款的網站建設流程,更有鷹潭免費網站建設讓你可以放心的選擇與我們合作。

核心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格式的文件都可以調用的;
這些都可以在本地建立對應的文件,進行調用,都可以實現。

以上是“Ajax核心框架函數有哪些”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注創新互聯行業資訊頻道!

分享題目:Ajax核心框架函數有哪些-創新互聯
網站地址:http://www.2m8n56k.cn/article8/esgop.html

成都網站建設公司_創新互聯,為您提供營銷型網站建設面包屑導航外貿網站建設品牌網站制作品牌網站設計云服務器

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:[email protected]。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

h5響應式網站建設
主站蜘蛛池模板: 狠狠色丁香久久综合网 | 国产精品免费看久久久久 | 九九九免费视频 | 美国一级免费毛片 | 久久色视频在线观看 | 国产成人精品视频免费 | 国产亚洲精品片a77777 | tube69xxx最新片 | 天堂资源8中文最新版在线 天堂最新版 | 国产欧美在线观看视频 | 亚洲欧美日韩中文字幕在线一 | 中文字幕在线视频观看 | 亚州免费 | 黄色网址www| 91亚洲精品一区二区在线观看 | 亚洲天堂在线观看视频 | 国产精品精品国产 | 国产精品久久自在自线观看 | 国产精品系列在线 | 性高湖久久久久久久久 | 美女一级ba大片免色野外 | 亚洲精品一区二区四季 | 99久久综合国产精品免费 | 午夜一级影院 | 成 人 黄 色 视频 免费观看 | 亚洲午夜18 | 看黄免费网站 | 中文久久 | 在线观看欧美一区 | 久久精品国产99久久72 | 成人在线不卡视频 | 欧美巨大video粗暴 | 麻豆视频一区 | 午夜一级片 | 久久88综合 | 国产欧美一区视频在线观看 | 免费人成黄页网站在线观看国产 | 国产精品欧美亚洲日本综合 | 国产午夜不卡在线观看视频666 | 亚洲成年人在线观看 | 免费一级欧美片在线观看 |