作者dream1x (Hao)
看板Ajax
标题[问题] 一直搞不出来 救救我吧大侠
时间Sun May 31 13:04:35 2009
google也估了
书也买了
基础差 总是搞不出来
书上有个范例
只是我是写php 他范例为asp
卡关! 大侠帮帮忙吧~~
--主页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>GET VS. POST</title>
<script language="javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject)
xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
else if(window.XMLHttpRequest)
xmlHttp = new XMLHttpRequest();
}
function createQueryString(){
var firstName = document.getElementById("firstName").value;
var birthday = document.getElementById("birthday").value;
var queryString = "firstName=" + firstName + "&birthday=" + birthday;
return encodeURI(encodeURI(queryString)); //两次编码解决中文乱码问题
}
function doRequestUsingGET(){
createXMLHttpRequest();
var queryString = "9-3.aspx?";
queryString += createQueryString() + "×tamp=" + new Date().getTime();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET",queryString);
xmlHttp.send(null);
}
function doRequestUsingPOST(){
createXMLHttpRequest();
var url = "9-3.aspx?timestamp=" + new Date().getTime();
var queryString = createQueryString();
xmlHttp.open("POST",url);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(queryString);
}
function handleStateChange(){
if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
var responseDiv = document.getElementById("serverResponse");
responseDiv.innerHTML = decodeURI(xmlHttp.responseText); //解码
}
}
</script>
</head>
<body>
<h2>输入姓名和生日</h2>
<form>
<input type="text" id="firstName" /><br>
<input type="text" id="birthday" />
</form>
<form>
<input type="button" value="GET" onclick="doRequestUsingGET();" /><br>
<input type="button" value="POST" onclick="doRequestUsingPOST();" />
</form>
<div id="serverResponse"></div>
</body>
</html>
-- 这里我不会转为php 怎麽改都没反应
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<%@ Import Namespace="System.Data" %>
<%
if(Request.HttpMethod == "POST")
Response.Write("POST: " + Request["firstName"] + ", your birthday is " + Request["birthday"]);
else if(Request.HttpMethod == "GET")
Response.Write("GET: " + Request["firstName"] + ", your birthday is " + Request["birthday"]);
%>
--
感谢!!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.71.22.3
1F:推 chph:既然你是用PHP, 那你买ASP的书做什麽? 05/31 13:37
2F:推 Kelunyang:好妙的问题XD 05/31 13:41
3F:推 aej:应该是手上只有asp.net的书 可是被要求用PHP做出来吧 05/31 15:27
4F:→ dream1x:只是想学 并没有谁要求之类的 ok 我会了! 05/31 20:39