欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php AJAX POST的使用實(shí)例代碼

 更新時(shí)間:2008年12月27日 23:31:42   作者:  
AJAX POST的使用實(shí)例 @ 2008-12-3 晚上調(diào)試成功
ajax.html
程序代碼
復(fù)制代碼 代碼如下:

<!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>兼容多瀏覽器的AJAX入門實(shí)例(超詳細(xì)注釋)</title>
<script type="text/javascript">
<!--
//Ajax是建立在XMLHttp組件下的技術(shù),本例詳細(xì)語(yǔ)法參考?jí)嚎s包內(nèi)xmlhttp手冊(cè)
var xmlHttp
//建立XMLHTTP對(duì)象調(diào)用MS的ActiveXObject方法,如果成功(IE瀏覽器)則使用MS ActiveX實(shí)例化創(chuàng)建一個(gè)XMLHTTP對(duì)象 非IE則轉(zhuǎn)用建立一個(gè)本地Javascript對(duì)象的XMLHttp對(duì)象(此方法確保不同瀏覽器下對(duì)AJAX的支持)
function createXMLHttp(){
if(window.XMLHttpRequest){ // Mozilla 瀏覽器
xmlHttp = new XMLHttpRequest();
}else if (window.ActiveXObject){ // IE 瀏覽器
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
}
//建立主過程
function startXMLHttp(){
createXMLHttp(); //建立xmlHttp 對(duì)象
var send_string="name="+document.getElementById("name").value;
send_string= encodeURI(send_string)
// alert(document.getElementById("text").value);
// return;
xmlHttp.onreadyStatechange =dodo; //xmlHttp下的onreadystatechange方法控制傳送過程
xmlHttp.open("post","ajax_show.php",true); //傳送方式 讀取的頁(yè)面 異步與否
// xmlHttp.setRequestHeader("cache-control","no-cache");
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(send_string); //發(fā)送
}
function dodo(){
if(xmlHttp.readyState==4){ // xmlHttp下的readystate方法 4表示傳送完畢
if(xmlHttp.status==200){ // xmlHttp的status方法讀取狀態(tài)(服務(wù)器HTTP狀態(tài)碼) 200對(duì)應(yīng)OK 404對(duì)應(yīng)Not Found(未找到)等
document.getElementById("content").innerHTML=xmlHttp.responseText //xmlHttp的responseText方法 得到讀取頁(yè)數(shù)據(jù)
}
}
}
-->
</script>
</head>
<body>
<span id="content">要替換的內(nèi)容</span><br>
<input type="button" onclick="javascript:startXMLHttp()" value="AJAX獲取"/>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="name" id="name" />
</label>
</form>
</body>
</html>

ajax_show.php
程序代碼
復(fù)制代碼 代碼如下:

<?php
$content = isset($_POST['name']) ? $_POST['name'] : '';
echo $content;
?>

相關(guān)文章

最新評(píng)論