前台操作页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="select.aspx.cs" Inherits="select" %><!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>
</head>
<body><script type="text/javascript">
            function aa(str){
                var xmlHttp;
                //var str=document.all.select1.options[document.all.select1.selectedIndex].value;
                try{
                    xmlHttp=new XMLHttpReauest();
                    
                }
                catch(e){
                    try{
                        xmlHttp=new ActiveXObject("Msxml.XMLHTTP");
                        
                    }
                    catch(e){
                        try{
                         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                         }
                      catch (e){
                         alert("您的浏览器不支持AJAX!");
                         return false;
                         }                    }
                }
                
                xmlHttp.onreadystatechange=function()
                {
                    if(xmlHttp.readyState==4)
                    {
                        document.form1.show_text.value=xmlHttp.responseText;
                        document.getElementById("txt").innerHTML=xmlHttp.responseText;
                    }
                }
                var url="select_show.aspx?a="+str;
                xmlHttp.open("GET",url,true);
                xmlHttp.send(null);
            }
            
        </script>
    <form id="form1" runat="server">
    <input name="show_text" type="text" />
    <select name="select1" onchange="aa(this.value)">
        <option value="新闻">新闻</option>
        <option value="产品">产品</option>
    </select>
    <div id="txt">  
      
    </div>    </form>
</body>
</html>服务器的页面
public partial class select_show : System.Web.UI.Page
{
    DB db = new DB();
    protected void Page_Load(object sender, EventArgs e)
    {
        write_table();
    }    protected void write_table()
    {
        string name = Request.Params["a"].ToString();        string sqlStr = "select * from allmess where typeCon='" + name + "'";
        DataSet ds = new DataSet();
        ds = db.get_ds(sqlStr);
        string str = "";
        Response.Write("<table border=1>");
        for (int a = 0; a < ds.Tables[0].Rows.Count; a++)
        {
            string aa = ds.Tables[0].Rows[a]["ID"].ToString();
            str += "<tr><td>";
            str += aa;
            str += "</td><td>";
            str += ds.Tables[0].Rows[a]["nameCon"].ToString(); str += "</td><td>" + ds.Tables[0].Rows[a]["createTime"].ToString() + "</td></tr>";
        }
        Response.Write(str);
        Response.Write("</table>");
    }
}
结果出来的是3。如果我把服务器的页面name参数改为一个具体的值不获取前台传过来的值的话就能显示。请问高手这个问题是怎么回事啊?

解决方案 »

  1.   

    alert(str)var url="select_show.aspx?a="+str; --
    看看这个是什么东西
      

  2.   

    str就是我要传的参数  
    <select name="select1" onchange="aa(this.value)"> 
            <option value="新闻">新闻 </option> 
            <option value="产品">产品 </option> 
        </select> 
    里面的值  这个我调试过 是对的
      

  3.   

    那你就单步进后台看看,
    看看他response的是什么字符串
      

  4.   

    返回的是只有table标签的字符串不知道怎么回事
      

  5.   


    看的值是正常的, 目的是不是看name里面有没有空格啊?
      

  6.   

    问题找出来了   name值传到服务器页面上的时候成乱码了,这个是怎么回事呢?
      

  7.   

    那是编码问题
    不会是乱码
    获取的时候是一样的Requst.QueryString[""]来获取
      

  8.   

    老大们  还是不可以哦  我用的string name = Request.QueryString["a"].ToString();
    结果调试出来的还是乱码哦。   求教高手们啦~~~~~~~~~~~~~
      

  9.   

    var url="select_show.aspx?a="+encodeURIComponent(str);