AJAX实现二级级联菜单,用PHP完成,客户端代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script type="text/javascript">
var xmlHttp;
var a =new Array();
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
}
function send_request(){
createXMLHttpRequest();
var year = document.getElementById("year");
var url = "check_2.php?page="+escape(year.value);
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = checkit;&n ......
前台HTML代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<style type="text/css">
a { text-decoration:none;}
</style>
<script type="text/javascript">
var xmlHttp;
function CreateXmlHttp()
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
function StartRequest(index)
{
// alert("1");
var url="repeater.aspx?index="+index+"&key="+escape(document.getElementById("tip").value);
//alert(url);
&n ......
客户端String.php,服务器端String_check.php,很简单的实现。
客户端代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function sendRequest(){
createXMLHttpRequest();
var name = document.getElementById("name").value;
url = "String_check.php?page="+name;
xmlHttp.onreadystatechange = callback;
xmlHttp.open('GET',url,true);
xmlHttp.send(null);
}
function callbac ......
利用AJAX动态获取当前时间,客户端time.php,服务器端time_check.php
客户端代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>动态显示时间</title>
</head>
<script language="javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
else{
alert("创建请求失败");
}
}
function sendRequest(){
createXMLHttpRequest();
url = "time_check.php";
xmlHttp.onreadystatechange = callback;
xmlHttp.open('GET',url,true);
xmlHttp.send(null);
}
function callback(){
if(xmlHttp.rea ......
有关ajax的其实就是1个类的使用:XMLHttpRequest.
首先要声明这个类的对象,鉴于各个浏览器把这个类嵌入的方式不同,声明的方式也不同:
var xmlHttpReq = null;
if (window.XMLHttpRequest) //Mozilla 浏览器
{
xmlHttpReq = new XMLHttpRequest();
}
else if (window.ActiveXObject) // IE浏览器
{
try
{
xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("您的浏览器不支持AJAX!") ;
}
}
}
else
{
alert("您的浏览器不支持AJAX!") ;
}
然后是open,send,getresponse
xmlHttpReq.open("POST","http://localhost///6gold/home_validate.php",true);
xmlHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttpReq.onreadystatechange = function()
{
if (xmlHttpReq.readyState == 4)
{
if (xmlHttpReq.status == 200)
{
......
ajax实现将鼠标放到图标上,下方会显示和该图有关的信息
客户端代码mouseover.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>鼠标悬浮测试</title>
</head>
<script type="text/javascript" language="javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function sendRequest(t){
var id = t.id
createXMLHttpRequest();
var url = "mouseover_check.php?page=" +t.id ;
xmlHttp.onreadystatechange = callback;
xmlHttp.open('GET',url,true);
xmlHttp.send(null);
}
function callback(){
......