var xmlHttp;
function Validation()
{
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    var name = document.getElementById("Text1");
    xmlHttp.open("post","run.aspx?name="+name.value);
    xmlHttp.onreadystatechange = onMessage();
    xmlHttp.Send(null);
}
function onMessage(){
    if(xmlHttp.readystate == 4 && xmlHttp.status == 200)
    {
    document.getElementById("now").innerHTML = "查询完成";
    }
    else if(xmlHttp.readystate == 1)
    {
    document.getElementById("now").innerHTML = "正在发送请求";
    }
        else if(xmlHttp.readystate == 2)
    {
    document.getElementById("now").innerHTML = "响应内容";
    }
        else if(xmlHttp.readystate == 3)
    {
    document.getElementById("now").innerHTML = "正在解析内容";
    }
}大家看下上面写的有错误吗???

解决方案 »

  1.   

    基本上没错,不过
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    的时候一般还会对别的浏览器做判断,
    基本上用的时候只用写
    if(xmlHttp.readystate == 4 && xmlHttp.status == 200) 就可以了。
      

  2.   

    为什么xmlHttp.readystate状态一直停留在1呢
      

  3.   

    你先在run.aspx页设置一个断点,看值传过来没有。
      

  4.   

     run.aspx.cs 代码:   好像没传过来啊~~怎么办呢   protected void Page_Load(object sender, EventArgs e)
        {
            string name = Request.QueryString["name"];
            if (name != null)
            {
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["test"].ConnectionString);
                SqlCommand cmd = new SqlCommand("selectTest", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@name", SqlDbType.VarChar, 40).Value = name;
                conn.Open();
                int count = (int)cmd.ExecuteScalar();
                conn.Close();
                if (count == 0)
                {
                    Response.Write("<script>alert('该用户可以用!');</script>");
                }
                else
                {
                    Response.Write("<script>alert('已被注册!');</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('error!');</script>");
            }
        }
      

  5.   

    你参照我这个写吧。自己再改下。    var xmlhttp;
        var DStatus="";
        var type="";
        var pid="";
        var did="";
        function DBalternating(type,pid,did)
        {      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");      xmlhttp.onreadystatechange=statechange;      xmlhttp.Open("POST","DBalternating .aspx?type="+type+"&pid="+pid+"&did="+did+"",true);      xmlhttp.Send();    }
        
        
        function statechange()
        {
          if(xmlhttp.readystate==4)
          {
            if(xmlhttp.status==200)
            { 
               // DStatus=xmlhttp.responseText;
                Message=xmlhttp.responseXML.getElementsByTagName("list");
             
    type=Message[0].getElementsByTagName("type")[0].text;
    pid=Message[0].getElementsByTagName("pid")[0].text;
    did=Message[0].getElementsByTagName("did")[0].text;
                 window.open('showvideo.aspx?type='+type+'&patientid='+pid+'&doctorid='+did+'');          
               
            }
          }
        }
      

  6.   

    run.aspx.cs 页面的Page_Load最开始就设了断点,但根本就运行不到断点那去~~~
      

  7.   

    解决啦~~~
    JS中   xmlHttp.onreadystatechange = onMessage();这句不能带括号~!!!写成这样就OK啦~~~~
    xmlHttp.onreadystatechange = onMessage;