客户端: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的值为空,不知什么原因?谢谢
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的值为空,不知什么原因?谢谢
xml.open("GET",url,false);
xml.open("GET",url,false);
不行,我试过了...
有时两者是不一样的!
------------------------------------------------
<%@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>
我的是ASP.NET环境哦....
服务器端测试的代码,我使用的是你的.net的代码。.net代码debug状态下,能够看到测试页面发送过来的数值。
------------------------------------------------------------------------------
<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来获取就可以了。