PHP100 ajax教程代碼
ajax.js
document.getElenentById('php100') 發送到指定標籤位置 標誌位名稱爲php100
inner.HTML 以HTML形式發送
=byphp100 獲取什麼內容? byphp100
xmlHttp.responseText 獲取xmlHttp.open中的內容
//判斷遊覽器
var xmlHttp;
function $_xmlHttprequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
//取得當前url的值
function funphp100(url){
$_xmlHttprequest();
xmlHttp.open("GET","for.php?id="+url,true);
xmlHttp.onreadystatechange = byphp;
xmlHttp.send(null);
}
//準備發送的方法 和 發送doucment.getElemnetById的使用
function byphp(){
var byphp100 = xmlHttp.responseText;
document.getElementById('php100').innerHTML = byphp100;
}
--------------------------------for.php-------------------------------------
<?
if($id=$_GET[id]){
if($i=0;$i<10;$i++){
echo $id;
}
exit()
}
?>
-----------------------------------index.php--------------------------------------
<script type="text/javascript" src="ajax.js"></script>
<a href="#" οnclick="funphp100('o')">o</a>
<a href="#" οnclick="funphp100('t')">t</a>
<a href="#" οnclick="funphp100('x')">x</a>
<div id="php100"></div>
document.getElenentById('php100') 發送到指定標籤位置 標誌位名稱爲php100
inner.HTML 以HTML形式發送
=byphp100 獲取什麼內容? byphp100
xmlHttp.responseText 獲取xmlHttp.open中的內容
//判斷遊覽器
var xmlHttp;
function $_xmlHttprequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
//取得當前url的值
function funphp100(url){
$_xmlHttprequest();
xmlHttp.open("GET","for.php?id="+url,true);
xmlHttp.onreadystatechange = byphp;
xmlHttp.send(null);
}
//準備發送的方法 和 發送doucment.getElemnetById的使用
function byphp(){
var byphp100 = xmlHttp.responseText;
document.getElementById('php100').innerHTML = byphp100;
}
--------------------------------for.php-------------------------------------
<?
if($id=$_GET[id]){
if($i=0;$i<10;$i++){
echo $id;
}
exit()
}
?>
-----------------------------------index.php--------------------------------------
<script type="text/javascript" src="ajax.js"></script>
<a href="#" οnclick="funphp100('o')">o</a>
<a href="#" οnclick="funphp100('t')">t</a>
<a href="#" οnclick="funphp100('x')">x</a>
<div id="php100"></div>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.