好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > Ajax 核心框架函數及例子

Ajax 核心框架函數及例子

熱門標簽:如何用地圖標注各分公司 辦理一個400電話多少錢 接聽電話機器人哪有 莆田防封電銷卡價格 信貸電銷機器人有用嗎 蓄意標記地圖標注 電銷機器人適用范圍 廣西ai語音電銷機器人哪家好 察縣地圖標注
核心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核心XMLHTTP組件資料
  • Javascript級聯下拉菜單以及AJAX數據驗證核心代碼
  • jquery ajax方式直接提交整個表單核心代碼
  • 解析ajax核心XMLHTTPRequest對象的創建與瀏覽器的兼容問題
  • Ajax核心技術代碼分享
  • Ajax核心XMLHttpRequest總結
  • 簡單談談AJAX核心對象

標簽:益陽 平涼 張掖 儋州 鷹潭 延邊 阿拉善盟 銅陵

巨人網絡通訊聲明:本文標題《Ajax 核心框架函數及例子》,本文關鍵詞  Ajax,核心,框架,函數,及,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Ajax 核心框架函數及例子》相關的同類信息!
  • 本頁收集關于Ajax 核心框架函數及例子的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 高H各种姿势调教1v1| 舔女人逼逼视频| 免费看成人| 捣得花汁飞溅h| 欧美精品孕妇分娩网站24小时免费| 不要乱碰瓷小说| nanana在线高清免费| 91在线|欧美:| 脱不掉的触手内裤h| 澳门一级毛片免费| 中文字幕欧美人妻精品一区蜜臀| 国模小黎第三套大尺度人体| 亚洲女人毛茸茸| 黄色免费看软件| 果冻传媒一二三区AV精品电影| 欧美一级做一级a做片性视频在线观看| 131美女做爰视频网站| 公交车强摁做开腿呻吟h男男 | 公与妇仑乱免费无码| 欧美一区网站| 午夜韩国理论片在线播放| 国产一区二区免费不卡在线播放| 日本巨爆乳揉大乳任人揉| 国产69精品久久久久久| 三级黄免费| 久久综合中文字幕| 91丨PORNY丨蝌蚪熟女| 魅魔~婬辱の教室动漫| 91丨九色丨国产?在线| 美女被吸乳羞羞漫画无尽| 国产浴室偷窥在线播放| 久久国产三级| 玩中年熟妇丝高跟A片| 乱Lun合集六小说| 黄台app下载软件免费大全| 男生操美女| 西西人体扒开大胆大尺度展露 | 色接久久| 日韩三级电影网站| 老熟女乱婬XXOO视频| 日久成瘾by是寒酥酥小说|