ajax xmlHttp.responseText
来源:互联网 发布:公共基础知识题库软件 编辑:程序博客网 时间:2024/05/22 01:48
xmlHttp.responseText
在写一个AJAX小实例的时候,发现一个奇怪的问题:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>时间显示</title>
</head>
<body>
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
if (window.XMLHttpRequest)
{// code for all new browsers
xmlHttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if(xmlHttp!=null)
{
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","Test.aspx",true);
xmlHttp.send(null);
}
}
</script>
<form name="myForm">
用户: <input type="text" name="username" onkeyup="ajaxFunction();" />
时间: <input type="text" name="time" />
</form>
</body>
</html>
<head>
<title>时间显示</title>
</head>
<body>
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
if (window.XMLHttpRequest)
{// code for all new browsers
xmlHttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if(xmlHttp!=null)
{
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","Test.aspx",true);
xmlHttp.send(null);
}
}
</script>
<form name="myForm">
用户: <input type="text" name="username" onkeyup="ajaxFunction();" />
时间: <input type="text" name="time" />
</form>
</body>
</html>
Test.aspx的c#代码为:
protected void Page_Load(object sender, EventArgs e)
{
Response.Expires = -1;
Response.Write(DateTime.Now.ToString()); //输出当前时间
}
{
Response.Expires = -1;
Response.Write(DateTime.Now.ToString()); //输出当前时间
}
通过xmlHttp.responseText返回的时间却是:当前时间和Test.aspx页面的HTML代码。
有人说,要清除Test.aspx页面上的所有HTML代码,这样返回的确实只有当前时间了。
偶然发现,在Response.Write后面加一句:Response.End(); 就能避免返回Test.aspx页面的HTML代码了,而无需清除页面的HTML。
protected void Page_Load(object sender, EventArgs e)
{
Response.Expires = -1;
Response.Write(DateTime.Now.ToString()); //输出当前时间
Response.End();
}
{
Response.Expires = -1;
Response.Write(DateTime.Now.ToString()); //输出当前时间
Response.End();
}
Response.End() 使 Web 服务器停止处理脚本并返回当前结果。文件中剩余的内容将不被处理。
0 0
- ajax xmlHttp.responseText
- xmlHttp.open xmlHttp.responseText讨论
- xmlHttp responseText 返回乱码问题解决
- AJAX responseText乱码解决
- Ajax学习---responseText
- Ajax学习---responseText
- 如何解决XmlHttp.responseText的乱码问题
- xmlHttp.responseText正常,xmlHttp.responseXML拿不到值的问题
- ajax的responseXML与responseText
- ajax responseText返回整个网页
- ajax XMLHttpRequest responseText返回值
- ajax异步如何返回responseText
- ajax的responseText是什么东西
- AJAX xmlHTTP
- AJAX XMLHttp
- ajax--xmlhttp
- Ajax XmlHttp
- PHP ,Javascript,XMLHTTP,ResponseText 乱码问题的解决
- SAP BAPI一览 史上最全
- BreakPoint调试
- 解决Ubuntu下在firefox中打开Microsoft Outlook Web Access中文乱码
- openfire集群,nginx负载均衡
- No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=arm64, VALID_ARCHS=armv7 armv7s).
- ajax xmlHttp.responseText
- argc和argv
- jQuery 队列queue
- myeclipse 10 反编译插件 安装
- 使用SourceTree将bitbucket的远程仓库回滚到某一次提交
- android 一个页面内 多个listview的实现
- 异速联(E-SoonLink)标准版
- 学术牛人是怎么写论文的!
- Linux Tomcat System.out.print 中文乱码