客户端:function window.onload(){
  window.setInterval("fresh()",1000)
}
function fresh(){
  var dt = new Date();
  var url = "abc.aspx?tmp='"+ dt.getTime()+"'";
  var xml = new ActiveXObject("Microsoft.XMLHTTP");
  xml.open("POST",url,false);
  xml.send();
}服务器端:abc.aspx.cx文件中:
private void Page_Load(object sender, System.EventArgs e) {
            
   // if(!this.IsPostBack){
       string strGet=System.Web.HttpContext.Current.Request.QueryString["tmp"];           
       System.Web.HttpContext.Current.Response.Write("time:"+strGet);
   //    }
}问题是在page_load中取到的tmp的值为空,不知什么原因?谢谢

解决方案 »

  1.   

    会不会是这个  if(!this.IsPostBack) 造成的?
    还有就是你测试下WebService是不是可以出正常结果的
      

  2.   

    if(!this.IsPostBack)这一句我删除了,也不行哦.
    我不会用WebService...
      

  3.   

    试一下
    string strGet = this.Request["tmp"];
      

  4.   

    string strGet = this.Request["tmp"];
    ---------------------------------------
    刚才试过了,不行,怎么回事呢?
      

  5.   

    调试一下abc.aspx.cs ,看看参数到底过来没
      

  6.   

    在.cs文件中取不到tmp的值...即为空.
      

  7.   

    刚才我取了this.Request.QueryString.Count的值竟然为0?
      

  8.   

    客户端用这个页面测试就会知道到底有没有把数值传递过去了。
    -----------------------------------
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="CP_ACP"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <%
    function getHTTPPage(url)
        dim Http
        set Http=server.createobject("MSXML2.XMLHTTP")
        Http.open "GET",url,false
        Http.send()
        if Http.readystate<>4 then 
            exit function
        end if
        getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
        set http=nothing
        if err.number<>0 then
    err.Clear
    end if
    end functionFunction BytesToBstr(body,Cset)
            dim objstream
            set objstream = Server.CreateObject("adodb.stream")
            objstream.Type = 1
            objstream.Mode =3
            objstream.Open
            objstream.Write body
            objstream.Position = 0
            objstream.Type = 2
            objstream.Charset = Cset
            BytesToBstr = objstream.ReadText 
            objstream.Close
            set objstream = nothing

    End Function
    %><title></title>
    </head><body>
    <%
    Dim Url,Html
    Url="http://localhost/CSharpWebAppTest/WebForm1.aspx?tmp=33333"
    Html = getHTTPPage(Url)
    Response.write Html
    %>
    </body>
    </html>
    ---------------------------------------
      

  9.   

    不知道你怎么调试的,我这里是对的:
    aspx.cs:
    private void Page_Load(object sender, System.EventArgs e)
    {
    Response.Write(Request.QueryString["tmp"]);
    return;
    }js:
    function fresh(){
      var dt = new Date();
      var url = "http://localhost/AspNetStudy/Download.aspx?tmp='"+ dt.getTime()+"'";
      var xml = new ActiveXObject("Microsoft.XMLHTTP");
      xml.open("POST",url,false);
      xml.send();
      alert(xml.responseText);
    }
    fresh();
      

  10.   

    你送出去的内容,服务器端是可以收到的。前面的代码没错。你需要的功能是什么?是用纯javascript实现“客户端把时间传过去,然后服务器端再送相应的内容回来?”还是其他。把需求描述一遍。
      

  11.   

    需求类似是用纯javascript实现“客户端把时间传过去,然后服务器端再送相应的内容回来”
      

  12.   

    客户端程序
    ------------------------------------------------------------------------------
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>Test</title>
    <script>
    function window.onload(){
      window.setInterval("fresh()",1000)
    }
    function fresh(){
    alert("fresh()");
      var dt = new Date();
      var url = "http://localhost/CSFantinyWebApp/abc.aspx?tmp='"+ dt.getTime()+"'";
      //var url = "http://localhost/fantiny/Default.aspx";
      var xml = new ActiveXObject("Microsoft.XMLHTTP");
      xml.open("GET",url,false);
      xml.send();  if(xml.readystate!=4){
         alert("a");
         return;
      }
       var objXML = xml.responseText;
       // mydiv.innerHTML = xml.responseText;
       test2(objXML);
    }
    function test2(obj){
    var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
    var root;
    var MyText;
    var MyNewNode;
    xmlDoc.async = false;
    xmlDoc.resolveExternals = false;
    xmlDoc.loadXML(obj);
    if (xmlDoc.parseError.errorCode != 0) {
    var myErr;
    myErr = xmlDoc.parseError;
    alert("You have error " + myErr.reason);
    }
    else {
    alert(xmlDoc.xml);
    mydiv.innerHTML = xmlDoc.xml;
    }
    }
    </script>
    </head><body>
    <DIV ID="mydiv"></DIV></body>
    </html>
    ------------------------------------------------------------------------------
    由于你服务器端采用的是response.write,为了满足XMLdocument的需求,
    所以服务器端的HTML只需要如下即可。
    -------------------------------abc.aspx html code---------------------------------
    <%@ Page language="c#" Codebehind="abc.aspx.cs" AutoEventWireup="false" Inherits="CSFantinyWebApp.WebForm1" %>
    --------------------------------abc.aspx cs code----------------------------------
    后台的Page_onload代码相应修改为
    ------------------------------------------------------------------------------
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    // if(!this.IsPostBack){
    string strGet=System.Web.HttpContext.Current.Request.QueryString["tmp"];           
    System.Web.HttpContext.Current.Response.Write("<p>time:"+strGet + "</p>");
    //    }
    }
    ------------------------------------------------------------------------------
    如果要扩展功能,你操作document的时候,应该按照xml推荐的来做。同时想获取某一部分内容,
    请按照getelementbytagname来获取就可以了。