2 回答

TA貢獻1833條經驗 獲得超4個贊
假設你有一個主頁面index.php
內容如下
<script type="text/javascript" src="ajax.js"></script>
<a href="#" onclick="ygg('o')">o</a>
<div id="divID"></div>
這是ajax.js頁面如下
var xmlHttp;
function $_xmlhttprequest(){
if(window.ActiveXObject){
xmlHttp= new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function ygg(url){
$_xmlhttprequest();
xmlHttp.open("GET","ygg.php?"+url,true);//通過該地址得到內容
xmlHttp.onreadystatechange=byphp;//準備 變量
xmlHttp.send(null);//發(fā)送
}
//方法
function byphp(){
if(xmlHttp.readyState==4){
var text1 = xmlHttp.responseText;
document.getElementById('divID').innerHTML = text1;
}
}
順便說下,這里有個ygg.php是得到內容的,最簡單的,你可以直接
<?php
echo $_GET[id];
?>
- 2 回答
- 0 關注
- 1281 瀏覽
添加回答
舉報