国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

AJAX簡介

AJAX 是一種在無需重新載入整個(gè)網(wǎng)頁的情況下,能夠更新部分網(wǎng)頁的技術(shù)。

一.ajax是什麼:
(1).ajax是非同步 JavaScript 和 XML,英文全程是Asynchronous JavaScript and XML。
(2).ajax可以透過與後臺進(jìn)行少量的資料交換,實(shí)現(xiàn)對局部網(wǎng)頁進(jìn)行非同步更新,避免了要刷新這個(gè)頁面的情況。
在通常情況下,如果要更新網(wǎng)頁的數(shù)據(jù),需要刷新整個(gè)頁面,如果利用ajax,那麼就可以只進(jìn)行局部刷新即可。

AJAX 工作原理

ajax.gif

二.AJAX是基於現(xiàn)有的Internet標(biāo)準(zhǔn):
ajax並不是新的技術(shù),而是基於現(xiàn)有的Internet標(biāo)準(zhǔn)與技術(shù):
(1).XMLHttpRequest 物件(非同步的與伺服器交換資料)。
(2).JavaScript/DOM (訊息顯示/互動(dòng))。
(3).CSS (給資料定義樣式)。
(4).XML (作為轉(zhuǎn)換資料的格式)。
三.程式碼實(shí)例:
上面對ajax做了一個(gè)基本介紹,下面就是一個(gè)簡單的程式碼實(shí)例,先感受一下它的作用:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://m.miracleart.cn/" />
<title>php中文網(wǎng)</title>
<script>
function loadXMLDoc(){
  var xmlhttp;
  if (window.XMLHttpRequest){
    xmlhttp=new XMLHttpRequest();
  }
  else{
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function(){
    if(xmlhttp.readyState==4 && xmlhttp.status==200){
      document.getElementById("show").innerHTML=xmlhttp.responseText;
    }
  }
  xmlhttp.open("GET","demo/ajax/txt/demo.txt",true);
  xmlhttp.send();
}
window.onload=function(){
  var obt=document.getElementById("bt");
  obt.onclick=function(){
    loadXMLDoc();
  }
}
</script>
</head>
<body>
<div id="show"><h2>原來的內(nèi)容</h2></div>
<button type="button" id="bt">查看效果</button>
</body>
</html>

程式碼中的demo/ajax/txt/demo.txt可變更路徑在本機(jī)創(chuàng)建,觀察效果。

#
繼續(xù)學(xué)習(xí)
||
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://m.miracleart.cn/" /> <title>php中文網(wǎng)</title> <script> function loadXMLDoc(){ var xmlhttp; if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); } else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if(xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById("show").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","demo/ajax/txt/demo.txt",true); xmlhttp.send(); } window.onload=function(){ var obt=document.getElementById("bt"); obt.onclick=function(){ loadXMLDoc(); } } </script> </head> <body> <div id="show"><h2>原來的內(nèi)容</h2></div> <button type="button" id="bt">查看效果</button> </body> </html>
提交重置程式碼