一个简单的php+ajax 例子php

/ / 2016-09-24   阅读:2493
<!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">   <he...
<!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>iframe tag test</title>  
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
<script type="text/javascript">  
 function showHint(str)  
{  
if (str=="")  
  {   
  alert("showHint()函数的参数不能为空!");  
  return  
  }  
xmlHttp=GetXmlHttpObject()  
if (xmlHttp==null)  
  {  
  alert ("您的浏览器不支持这个请求!")  
  return  
  }   
var url="test1.php"  
url=url+"?q="+str  
url=url+"&sid="+Math.random()  
xmlHttp.onreadystatechange=stateChanged   
xmlHttp.open("GET",url,true)  
xmlHttp.send(null)  
}   
  
  
function stateChanged()   
{   
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")  
 {   
 var neirong=xmlHttp.responseText ;  
 alert(neirong);  
 }   
}  
  
  
function GetXmlHttpObject()  
{  
var xmlHttp=null;  
try  
 {  
 // Firefox, Opera 8.0+, Safari  
 xmlHttp=new XMLHttpRequest();  
 }  
catch (e)  
 {  
 // Internet Explorer  
 try  
  {  
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  
  }  
 catch (e)  
  {  
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  
  }  
 }  
return xmlHttp;  
}   
   
    </script>  
  
  
</head>  
<body >  
<input type="submit" name="button" id="button" value="提交"  onclick="showHint('ok');"/>  
</body>  

</html>


test1.php的代码:
<?php  
$q=$_GET["q"];  
if($q=="ok"){  
$response="888888";  
}else{  
$response="99999";  
    }  
echo $response;  
?>

我要评论

昵称:
验证码:

最新评论

共0条 共0页 10条/页 首页 上一页 下一页 尾页
意见反馈