21,886
社区成员
发帖
与我相关
我的任务
分享
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta http-equiv="expires" content="Thu, 01 Jan 1970 00:00:01 GMT" />
<meta http-equiv="expires" content="0" />
<script language="javascript">
var xmlHttp = "";
function createXML()//建立XMLHttp对象
{
xmlHttp = new window.XMLHttpRequest();
}
function handStateChange()
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
parseResult();
}
}
}
function parseResult()//解析请求结果
{
var serverResponse = document.getElementById("serverResponse");
if(serverResponse.hasChildNodes())
{
serverResponse.removeChild(serverResponse.firstChild);
}
serverResponse.appendChild(document.createTextNode(xmlHttp.responseText));
}
function createQueryString()//建立查询字符串
{
var FirstName = document.getElementById("FirstName").value;
var MiddleName = document.getElementById("MiddleName").value;
var Birthday = document.getElementById("Birthday").value;
return "FirstName=" + encodeURIComponent(FirstName) + "&MiddleName=" + encodeURIComponent(MiddleName) + "&Birthday=" + encodeURIComponent(Birthday);
}
function RequestGet()//处理get请求
{
createXML();
var url = "example1-get.php?date=" + new Date().getTime() + "&" + createQueryString();
xmlHttp.onreadystatechange = handStateChange;
xmlHttp.open("get",url,true);
xmlHttp.send(null);
}
function RequestPost()//处理post请求
{
createXML();
var url = "example1-post.php?date=" + new Date().getTime();
xmlHttp.onreadystatechange = handStateChange;
xmlHttp.open("post",url,true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlHttp.send(createQueryString());
}
</script>
<body>
<h1>Enter your firstName,MiddloeName,and Birthday:</h1>
<table>
<tbody>
<tr>
<td>FirstName:</td>
<td><input type="text" id ="FirstName" /></td>
</tr>
<tr>
<td>MiddleName:</td>
<td><input type="text" id ="MiddleName" /></td>
</tr>
<tr>
<td>Birthday:</td>
<td><input type="text" id ="Birthday" /></td>
</tr>
</tbody>
</table>
<input type="button" value="get" onclick="RequestGet()"/><br>
<input type="button" value="post" onclick="RequestPost()"/><br>
<h2>Server Response</h2>
<div id="serverResponse"></div>
</body>
$string = "你好 " . iconv("utf-8","gb2312",$_GET['FirstName']) . iconv("utf-8","gb2312",$_GET['MiddleName']) . " 您的生日是: " . iconv("utf-8","gb2312",$_GET['Birthday']);
echo $string;
$string = "你好 " . iconv("utf-8","gb2312",$_POST['FirstName']) . iconv("utf-8","gb2312",$_POST['MiddleName']) . " 您的生日是: " . iconv("utf-8","gb2312",$_POST['Birthday']);
echo $string;