ajax发送请求参数

meteorlyang 2009-04-27 09:54:49
刚开始学习AJAX,照着书做了一个列子就是网上很多都有的一个发送请求参数的列子。但是他的后台是用JAVA而我想用C#。有没有现成的列子呢,或是大家解释一下
这个是getAndPostExample.html
<script type="text/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 middleName=document.getElementById("middleName").value;
var birthday=document.getElementById("birthday").value;
var queryString="firstName"+firstName+"&middleName"+middleName+"&birthday"+birthday;
return queryString;
}
function doRequestUsingGET()
{
createXMLHttpRequest();
var queryString="GetAndPostExample?";
queryString=queryString+createQueryString()+"×tamp="+new Date().getTime();
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.open("GET",queryString,true);
xmlHttp.send(null);
}
function doRequestUsingPOST()
{
createXMLHttpRequest();
var url="GetAndPostExample?timeStamp="+new Date().getTime();
var queryString=createQueryString();
xmlHttp.open("POST",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlhttp.send(queryString);
}
function handleStateChange()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
parseResults();
}
}
}
function parseResults()
{
var responseDiv=document.getElementById("serverResponse");
if(responseDiv.hasChildNodes())
{
responseDiv.removeChild(responseDiv.childNodes[0]);
}
var responseText=document.createTextNode(xmlHttp.responseText);
responseDiv.appendChild(responseText);
}
</script>
这个是java
代码清单3-8 向浏览器回显名、姓和生日

package ajaxbook.chap3;



import java.io.*;

import java.net.*;

import javax.servlet.*;

import javax.servlet.http.*;



public class GetAndPostExample extends HttpServlet {



protected void processRequest(HttpServletRequest request,

HttpServletResponse response, String method)

throws ServletException, IOException {



//Set content type of the response to text/xml

response.setContentType("text/xml");



//Get the user's input

String firstName = request.getParameter("firstName");

String middleName = request.getParameter("middleName");

String birthday = request.getParameter("birthday");



//Create the response text

String responseText = "Hello " + firstName + " " + middleName

+ ". Your birthday is " + birthday + "."

+ " [Method: " + method + "]";



//Write the response back to the browser

PrintWriter out = response.getWriter();

out.println(responseText);



//Close the writer

out.close();

}



protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

//Process the request in method processRequest

processRequest(request, response, "GET");

}



protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

//Process the request in method processRequest

processRequest(request, response, "POST");

}

}

如何用C#来实现呢???
...全文
142 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
function createXMLHttpRequest() //完成XMLHttpRequest对象初始化
function createQueryString() //得到需要的值
function doRequestUsingGET() function doRequestUsingPOST() //使用GET或者POST方法
function handleStateChange() //判断响应是否完成
function parseResults() //上面的那个函数响应成功,则用这个函数来处理信息

C#不会。


52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧