createXmlHttpRequest()函数后少了个return xmlHttp;
编码我觉得还是用encodeURIComponent的好,var queryString="n="+n+"&p="+p; return encodeURI(encodeURI(queryString)); 这两句变为
return "n="+encodeURIComponent(n)+"&p="+encodeURIComponent(p)就行了
xmlHttp.onreadystatechange=handlestatechange;就是这样的,我一般不这么写.
    var xmlHttp = createXMLHttpRequest();
    xmlHttp.onreadystatechange = function(){
        if(xmlHttp.readyState == 4){
            if(xmlHttp.status == 200){
      fg =  xmlHttp.responseText; 
  if(parseInt(fg,10)==1){
  alert(suc_msg);
  }
  else{alert(fal_msg);}   
}
        }
        else{alert("正在删除,请稍候");}
    }
    xmlHttp.open("get", url, true);
    xmlHttp.send(null);

解决方案 »

  1.   

    IE中:document.body.onload = inject; //Function inject()在这之前已被实现
    如果要加传递参数,可以做个闭包
    <body>
    </body>
    <script>
    (function(arg){   document.body.onload=function(){inject(arg);};})("a")function inject(a){alert(a);}
    </script>
      

  2.   

    不是调用,handlestatechange是函数名称,
    xmlHttp.onreadystatechange=handlestatechange,把函数赋给xmlHttp.onreadystatechange,xmlHttp.onreadystatechange用的是handlestatechange函数
    xmlHttp.onreadystatechange=handlestatechange()指,把handlestatechange函数的运算结果给xmlHttp.onreadystatechange
    不是一个概念
    如果要传递参数,就得像3楼一样用闭包
      

  3.   

      恩  4楼说的 很仔细 谢谢 明白了!  可是大家看我的代码 有什么问题啊?老是不能实现对了  我这里写下 1.aspx的内容:
    <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
    <%@ Import Namespace="System.Data" %>
    <%
    if(Request.HttpMethood =="POST")
    Response.Write("POST:"+Request["n"]+",you p is "+Request["p"]);
    else (Request.HttpMethood =="GET")
    Response.Write("GET:"+Request["n"]+",you p is "+Request["p"]);
    %>
      

  4.   


    <% 
    if(Request.HttpMethood =="POST") 
    {
    Response.Clear();
    Response.Write("POST:"+Request["n"]+",you p is "+Request["p"]); 
    Response.End();
    }
    else (Request.HttpMethood =="GET") 
    {
    Response.Clear();
    Response.Write("GET:"+Request["n"]+",you p is "+Request["p"]); 
    Response.End();
    }
    %>
      

  5.   

    晕啊   定义了var xmlHttp;  这个还是有错的
      

  6.   

    if (...)
    else (...)
    没见过这种语法
      

  7.   


    突然发现else(……)……这个有点汗。。
      

  8.   

    <input type="button" name="" value="get" onclick="getp();" />  调用 下面有个id为serverResponse的层  用于显示传过来的内容的!!
    js中的: 
    function creatQueryString(){ 
    var n=document.getElementById("n").value; 
    var p=document.getElementById("p").value; 
    var queryString="n="+n+"&p="+p; 
    return encodeURI(encodeURI(queryString)); 

    function createXmlHttpRequest(){ 
      if(window.ActiveXObject) 
            xmlHttp=new ActiveXObject("Microsoft.XmlHttp"); 
          else if (window.XmlHttpRequest) 
      xmlHttp=new XmlHttpRequest(); 
    } function handlestatechange(){ 
    if(xmlHttp.readyState==4 && xmlHttp.status==200){ 
    var responseDiv=document.getElementById("serverResponse"); 
    responseDiv.innerHTML=decodeURI(xmlHttp.responseText); } 

    function getp(){ createXmlHttpRequest(); 
    var queryString="1.aspx?"; 
    queryString +=creatQueryString()+"&time="+new Date().getTime(); 
    xmlHttp.onreadystatechange=handlestatechange; 
    xmlHttp.open("GET",queryString); 
    xmlHttp.send(null); }
    这个是html中的 <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %> 
    <%@ Import Namespace="System.Data" %> 
    <% 
    if(Request.HttpMethood =="POST") 
    Response.Write("POST:"+Request["n"]+",you p is "+Request["p"]); 
    else if(Request.HttpMethood =="GET") 
    Response.Write("GET:"+Request["n"]+",you p is "+Request["p"]); 
    %>
    这个是1.aspx中的运行后 并没有在 id为serverResponse的层中显示  而去浏览器也没报错!
      

  9.   

    应该没什么问题,检查一下,看是否var n=document.getElementById("n").value; 
    var p=document.getElementById("p").value; 没有给n和p获取到值
      

  10.   

    if(Request.HttpMethood =="POST") 
    Response.Write("POST:"+Request["n"]+",you p is "+Request["p"]); 
    else if(Request.HttpMethood =="GET") 
    Response.Write("GET:"+Request["n"]+",you p is "+Request["p"]);这个执行了没?
      

  11.   

    确认下xmlHttp.responseText是否有值
    如果没有值,就应该是服务器方的问题了
      

  12.   


    if(window.ActiveXObject) 
            xmlHttp=new ActiveXObject("Microsoft.XmlHttp"); 改为
    if(window.ActiveXObject) 
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 试试
      

  13.   

    你的xmlhttprequest对像初始化有问题
    最好是放到函数外面执行<script language="javascript">
    <body>
    <input id="n"><input id="p">
    <div id="1"></div>
    </body>
    <script language="javascript"> 
    var xmlHttp=false;
    try{
        xmlHttp=new XmlHttpRequest();
    }catch(tryMicrosoftIE){
        try{
            xmlHttp=new ActiveXObject("msxml2.XMLHTTP");
        }catch(tryOtherMicrosoftIE){
            try{
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }catch(failed){
                xmlHttp=false;
            }
        }
    }
    if(xmlHttp) alert("xmlhttprequest对像初始化失败");
     function creatQueryString(){ 
    var n=document.getElementById("n").value; 
    var p=document.getElementById("p").value; 
    var queryString="n="+n+"&p="+p; 
    return queryString; 
    } function handlestatechange(){ 
    if(xmlHttp.readyState==4 && xmlHttp.status==200){ 
    var responseDiv=document.getElementById("1"); 
    responseDiv.innerHTML=decodeURI(xmlHttp.responseText); 
    }

    function getp(){ 
    //createXmlHttpRequest(); 
    var queryString="1.html?"; 
    queryString +=creatQueryString()+"&time="+new Date().getTime(); 
    xmlHttp.onreadystatechange=handlestatechange; 
    xmlHttp.open("GET",queryString,true); 
    xmlHttp.send(null); 
    } getp();
    </script> </script>