其实在网上搜的到很多,但大部分只写了前台js代码:
    //发送请求函数   
    function sendRequestPost(url,param){   
        createXMLHttpRequest();   
        xmlHttpRequest.open("POST",url,true);   
        xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");   
        xmlHttpRequest.onreadystatechange = processResponse;   
        xmlHttpRequest.send(param);   
    } 
            var url = "Default2.aspx";   
            var param = "userName="+userName+"&psw="+psw;   
            sendRequestPost(url,param);       但是我不知道在后台也就是Default2.aspx页面怎么接收这些参数,网上找的代码都不全面。
现在我要做的是提交评论,有题标内容什么的,提交完后无刷新显示在当前页面的Repeater上(我们老大不让用.net自带的Ajax框架),get方式提交我会但内容一多就会丢失!所以想用Post方式,但不会。谁有完整代码给我看看,发我邮箱上也行:[email protected]  谢谢各位大虾了!

解决方案 »

  1.   

    后台也就是Default2.aspx页面???
    这文件是 后台吗?不用自带的,那你用 AJAX2.0 ,去下一个DLL 引用就行
      

  2.   

    利用XMLHttpRequest对象异步发送XML文档http://blog.csdn.net/Sandy945/archive/2009/05/12/4170512.aspx
      

  3.   

    post到Default2.aspx的url就是Default2.aspx?userName=yourusername&psw=yourpassword在后台的Page_Load用Request.Form["userName"]获取参数数值
      

  4.   


    这样就可以了,都在PageLoad里取
      

  5.   

    我这里有一个jqery的无刷新跳转页面的例子,不过没有将值传掉另外的一个页面。是无刷新的显示评论页面
      

  6.   

    特意帮你敲了一个:
    Default.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="AjaxData" %><!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 runat="server">
        <title>无标题页</title>
        <script type="text/javascript">
            
            var xmlHttp;
            
            function createXMLHttpRequest()
            {
                if(window.ActiveXObject)
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                else if(window.XMLHttpRequest)
                    xmlHttp=new XMLHttpRequest();
            }
            
            function postTJ(str)
            {
                createXMLHttpRequest();
                
                xmlHttp.open("post","AjaxData.aspx",true);
                xmlHttp.onreadystatechange=stateChange;            xmlHttp.setRequestHeader("content-type","application/x-www-form-urlencoded"); 
                
                xmlHttp.send("str="+str+"&date="+new Date().getTime());
            }
            
            function stateChange()
            {
                if(xmlHttp.readyState==4)
                {
                    if(xmlHttp.status==200)
                    {
                        alert(xmlHttp.responseText);
                    }
                }
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input type="button" onclick="postTJ('wujj')" value="Post">
        </div>
        </form>
    </body>
    </html>AjaxData.aspx.csusing System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(Request.Form["str"]+"--好好学习");        Response.End();
        }
    }
      

  7.   

    建两个页面,一个是 Default.aspx 一个是 AjaxData.aspx
      

  8.   

    都说了是post方法,还在ULR上传值,那样不就是GET方法了,我会做。本页面是Default1.aspx
    Default2.aspx是处理Ajax的页面。数据通过post方式提交到Default2.aspx,在Default2.aspx做提交到数据库的操作。在返回处理结果到Default1.aspx,实现无刷新操作
      

  9.   

    上面已经都说完了,不过对于后面Default的html页,最好把代码都删掉,不然你读出来的数据可能不是你想直接返回的数据。
      

  10.   


    你从哪看到是从url上传了?
      

  11.   


    加一句  Response.End()  就好了
      

  12.   

    request.form["...."] 来取传过来的值
      

  13.   

    用JQuery简单啊。$.ajax({url:"post.aspx",type:"post",datatype:"html",data:"id=10",success:function(msg){if(msg=="true"){alert("保存成功!");}else{alert("保存失败!");}}});这就是用post方法将id传到post.aspx去了。post.aspx处理完以后,直接返回一个字符串,如果成功则返回"true",如果失败随便返回什么,或者错误信息。
      

  14.   

    xmlHttp.open("POST", "test.aspx",true);
    xmlHttp.onreadystatechange=function()
    {
     if(xmlHttp.readyState==4)
     {
      if(xmlHttp.status==200)alert(xmlHttp.responseText);
      else alert("发生错误!");
     }
    }
    xmlHttp.send("");
    if(Request.Form["a"]!=null){}
      

  15.   


        <script type="text/javascript">
            $(document).ready(function(){
                $("#div1").ajaxStart(function(){
                    $("#div1").html("正在加载");
                });
            
                $("#btn1").click(function(){
                    $.post("jQuery.aspx",{key:'btn1',name:$("#txt").val()},function(msg){
                        $("#div1").html(msg);
                    });   
            });
        </script>        <input type="button" id="btn1" value="btn1" />
            <div id="div1"></div>    protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Form["key"] == "btn1")
            {
                string name = Request.Form["name"];
                Response.Clear();
                Response.Write(GetClass(name));
                Response.End();
            }    }    private string GetClass(string name)
        {
            SqlConnection con = new SqlConnection("server=.;database=stu;uid=sa;pwd=sa");
            SqlDataAdapter sda = new SqlDataAdapter("select class from stu where name='" + name + "'", con);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return ds.Tables[0].Rows[0]["class"].ToString();
            }
            else
            {
                return "此人无对应的班级。";
            }
        }
      

  16.   

    protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Form["key"] == "btn1")
            {
                string name = Request.Form["name"];
                Response.Clear();
                Response.Write(GetClass(name));
                Response.End();
            }    }