av手机免费在线观看,国产女人在线视频,国产xxxx免费,捆绑调教一二三区,97影院最新理论片,色之久久综合,国产精品日韩欧美一区二区三区

AJAX

AJAX請(qǐng)求類實(shí)例代碼

時(shí)間:2024-10-10 17:25:28 AJAX 我要投稿
  • 相關(guān)推薦

AJAX請(qǐng)求類實(shí)例代碼

  代碼如下:

  // AJAX類

  function AJAXRequest() {

  var xmlObj = false;

  var CBfunc,ObjSelf;

  ObjSelf=this;

  try { xmlObj=new XMLHttpRequest; }

  catch(e) {

  try { xmlObj=new ActiveXObject("MSXML2.XMLHTTP"); }

  catch(e2) {

  try { xmlObj=new ActiveXObject("Microsoft.XMLHTTP"); }

  catch(e3) { xmlObj=false; }

  }

  }

  if (!xmlObj) return false;

  this.method="POST";

  this.url;

  this.async=true;

  this.content="";

  this.callback=function(cbobj) {return;}

  this.send=function() {

  if(!this.method||!this.url||!this.async) return false;

  xmlObj.open (this.method, this.url, this.async);

  if(this.method=="POST") xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

  xmlObj.onreadystatechange=function() {

  if(xmlObj.readyState==4) {

  if(xmlObj.status==200) {

  ObjSelf.callback(xmlObj);

  }

  }

  }

  if(this.method=="POST") xmlObj.send(this.content);

  else xmlObj.send(null);

  }

  }

  AJAX請(qǐng)求類

  by HotHeart(熱血心腸)

  Site: http://www.xujiwei.cn/

  Blog: http://www.xujiwei.cn/blog/

  類名:AJAX

  創(chuàng)建方法:var ajaxobj=new AJAX;,如果創(chuàng)建失敗則返回false

  屬性:method - 請(qǐng)求方法,字符串,POST或者GET,默認(rèn)為POST

  url - 請(qǐng)求URL,字符串,默認(rèn)為空

  async - 是否異步,true為異步,false為同步,默認(rèn)為true

  content - 請(qǐng)求的內(nèi)容,如果請(qǐng)求方法為POST需要設(shè)定此屬性,默認(rèn)為空

  callback - 回調(diào)函數(shù),即返回響應(yīng)內(nèi)容時(shí)調(diào)用的函數(shù),默認(rèn)為直接返回,回調(diào)函數(shù)有一個(gè)參數(shù)為XMLHttpRequest對(duì)象,即定義回調(diào)函數(shù)時(shí)要這樣:function mycallback(xmlobj)

  方法:send() - 發(fā)送請(qǐng)求,無參數(shù)

  一個(gè)例子:

  var ajaxobj=new AJAXRequest; // 創(chuàng)建AJAX對(duì)象

  ajaxobj.method="GET"; // 設(shè)置請(qǐng)求方式為GET

  ajaxobj.url="default.asp" // URL為default.asp

  // 設(shè)置回調(diào)函數(shù),輸出響應(yīng)內(nèi)容

  ajaxobj.callback=function(xmlobj) {

  document.write(xmlobj.responseText);

  }

  ajaxobj.send(); // 發(fā)送請(qǐng)求

【AJAX請(qǐng)求類實(shí)例代碼】相關(guān)文章:

原生ajax調(diào)用數(shù)據(jù)實(shí)例簡(jiǎn)單講解07-19

數(shù)控編程代碼大全02-13

Java代碼的基本知識(shí)09-03

網(wǎng)頁(yè)滾動(dòng)文字的制作HTML代碼04-10

硬盤邏輯故障解決方法實(shí)例07-16

excel中驗(yàn)算公式使用實(shí)例介紹12-08

公文寫作四個(gè)技巧及實(shí)例10-14

2024小升初數(shù)學(xué)濃度問題實(shí)例解答06-07

損益類科目有哪些07-09

飲食類日語(yǔ)詞匯11-15