[php]
//-----------------------------------------------
//CreateXMLHttpRequest
//-----------------------------------------------
function createRequest()
{
if(typeof XMLHttpRequest!="undefined")
{
return new XMLHttpRequest();
}
else if(typeof ActiveXObject!="undefined")
{
var xmlHttp_ver = false;
var xmlHttp_vers = ["MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp","Microsoft.XmlHttp"];
if(!xmlHttp_ver)
{
for(var i=0;i);
xmlHttp_ver = xmlHttp_vers;
break;
}
catch(oError){;}
}
}
if(xmlHttp_ver)
{
return new ActiveXObject(xmlHttp_ver);
}
else
{
throw new Error("Could not create XML HTTP Request.");
}
}
else
{
throw new Error("Your browser doesn't support an XML HTTP Request.");
}
}
var xmlHttp1;
var xmlHttp2;
//-----------------------------------------------
//SendRequest
//-----------------------------------------------
function SendRequest_News(urlName)
{
xmlHttp1 = createRequest();
xmlHttp1.open("GET", urlName, true);
xmlHttp1.onreadystatechange = ProcessRequest_News;
xmlHttp1.send(null);
}
//-----------------------------------------------
//SendRequest
//-----------------------------------------------
function SendRequest_Brand(urlName)
{
xmlHttp2 = createRequest();
xmlHttp2.open("GET", urlName, true);
xmlHttp2.onreadystatechange = ProcessRequest_Brand;
xmlHttp2.send(null);
}
//-----------------------------------------------
//ProcessRequest
//-----------------------------------------------
function ProcessRequest_News()
{
var divName = document.getElementById("div_news");
if(xmlHttp1.readyState == 4)
{
if(xmlHttp1.status == 200)
{
divName.innerHTML = xmlHttp1.responseText;
}
}
}
//-----------------------------------------------
//ProcessRequest
//-----------------------------------------------
function ProcessRequest_Brand()
{
var divName = document.getElementById("div_brand");
if(xmlHttp2.readyState == 4)
{
if(xmlHttp2.status == 200)
{
divName.innerHTML = xmlHttp2.responseText;
}
}
}
//-----------------------------------------------
//showTable
//-----------------------------------------------
function showTable()
{
SendRequest_News("index_news.php?status=load");
SendRequest_Brand("index_brand.php?status=load");
}
//-----------------------------------------------
//showLoad
//-----------------------------------------------
function showLoad()
{
showTable();
}
//-----------------------------------------------
[/php]
[php]
AJAX
<script language=javascript src="index.js"></script>
[/php]
[php]
<?
include("config.php");
if($_GET["status"] == "load")
{
index_news();
}
//-----------------------------------------------
//显示最新消息
//-----------------------------------------------
function index_news()
{
global $db;
$sql = "SELECT * FROM ajax_news ORDER BY news_id asc";
$rst = $db->query($sql);
echo "";
while($row = $db->fetch_array($rst))
{
echo " ";
echo " | ".$row[news_name]." | ";
echo "
";
}
echo "
";
}
//-----------------------------------------------
?>
[/php]
[ 本帖最后由 ysoo 于 2007-2-10 05:50 PM 编辑 ]