Ajax新手请教初级问题

骑驴快跑 2012-04-04 03:04:37

<script type="text/javascript">
window.onload = function()
{
try
{
var xmlhttp = new XMLHttpRequest();
}
catch(e)
{
var xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.open('GET','WebForm1.aspx',true);
xmlhttp.setRequestHeader('COOKIE','author=Robin Chen');
xmlhttp.onreadystatechange=function()
{
document.body.innerHTML+='<div>readyState:'+xmlhttp.readyState+'</div>';
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.body.innerHTML+='<div>responseText:'+xmlhttp.responseText+'</div>';
//alert(xmlhttp.responseText); //这句打印出来把前台页面都打印出来了
}
}
xmlhttp.send();
}
</script>


string strName = HttpContext.Current.Request.QueryString["author"]; //这个author值得不到
string strRes = "This is the response from the server:\r\n" + "Hello, " + strName + "!";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strRes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();

最终打印的结果应该是
readyState:1
readyState:2
readyState:3
readyState:4
responseText:Robin Chen
...全文
117 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
SomethingJack 2012-04-05
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

引用 2 楼 的回复:
直接用xmlhttp 兼容问题挺头痛,直接用jquery 的ajax吧,写起来方便,兼容性好,比如用你上面的例子

JScript code


$(document).ready(function() {
$.get("WebForm1.aspx",function(data){
$("body").html(data);
……

++
[/Quote]
+2
Acesidonu 2012-04-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
直接用xmlhttp 兼容问题挺头痛,直接用jquery 的ajax吧,写起来方便,兼容性好,比如用你上面的例子

JScript code


$(document).ready(function() {
$.get("WebForm1.aspx",function(data){
$("body").html(data);
……
[/Quote]
++
wzhiyuan 2012-04-04
  • 打赏
  • 举报
回复
直接用xmlhttp 兼容问题挺头痛,直接用jquery 的ajax吧,写起来方便,兼容性好,比如用你上面的例子

$(document).ready(function() {
$.get("WebForm1.aspx",function(data){
$("body").html(data);
});
});
骑驴快跑 2012-04-04
  • 打赏
  • 举报
回复
后台有误,高手只需帮我得到最终结果就行,现在responseText:是空值,后台那块不太会写

52,782

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧