Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 18, 2012 08:37 AM by shtrudel
Member
461 Points
540 Posts
Jan 16, 2012 10:41 AM|LINK
Hi there,
I am trying to play with the XMLHttpRequest object.
The calling page called test5.aspx listed here -
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function doIt() { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("mess").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET", "test3.aspx", true); xmlhttp.send(); } </script> </head> <body> <form id="form1" runat="server"> <div> <input id="Button1" type="button" value="button" onclick="doIt();" /> <div id="mess" style="position:absolute; top:100px; left:200px; background-color:Green;padding:10px">XXX</div> </div> </form> </body> </html>
And the test3.asp which have only Page_load handler that follows -
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load Response.Write("Hello") End Sub
When debugging the xmlhttp.responseText contain the following string -
"Hello <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title> </title></head> <body> <form method="post" action="test3.aspx" id="form2"> <div class="aspNetHidden"> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZJxfz6U3VS/7UkJ5oD68Qel0TGY563LKXIeDJckRIxjr" /> </div> </form> </body> </html> "
and I get Unknown Runtime Error.
What am I doing wrong ?
296 Points
60 Posts
Jan 16, 2012 11:05 AM|LINK
Hi when i done from my side your code it's working perfect.
Jan 16, 2012 11:07 AM|LINK
Hmmm,
Now I am really worried...
Jan 16, 2012 11:16 AM|LINK
Don't you get Runtime Error ?
What do you get in the xmlhttp variable when debugging ?
Jan 16, 2012 11:23 AM|LINK
hey im sorry,
i tesetd in c# working fine,vb im checking now
problem with responsetext contains "\n\r" which is not allowing to set to div
Jan 16, 2012 11:32 AM|LINK
i got the problem,
but i dont know exact reason
if we comment Response.Write in code behind it started workin
Jan 16, 2012 11:39 AM|LINK
san SanZ if we comment Response.Write in code behind it started workin
Not working for me even if I comment the Response.write...
Thanks for your effort
All-Star
22367 Points
2704 Posts
Microsoft
Jan 18, 2012 03:00 AM|LINK
Hello
As you are in the Page_Load event, so the full page's content is returned to the user.
For an AJAX request, you may try Render event to output the response content.
For example
protected override void Render(HtmlTextWriter output) { output.Write("Hello World"); }
Jan 18, 2012 08:37 AM|LINK
THANK YOU !
shtrudel
Member
461 Points
540 Posts
XMLHttpRequest question
Jan 16, 2012 10:41 AM|LINK
Hi there,
I am trying to play with the XMLHttpRequest object.
The calling page called test5.aspx listed here -
And the test3.asp which have only Page_load handler that follows -
When debugging the xmlhttp.responseText contain the following string -
"Hello
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
<form method="post" action="test3.aspx" id="form2">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZJxfz6U3VS/7UkJ5oD68Qel0TGY563LKXIeDJckRIxjr" />
</div>
</form>
</body>
</html>
"
and I get Unknown Runtime Error.
What am I doing wrong ?
san SanZ
Member
296 Points
60 Posts
Re: XMLHttpRequest question
Jan 16, 2012 11:05 AM|LINK
Hi when i done from my side your code it's working perfect.
-- If you find this post helpful then please "Mark As Answer"
shtrudel
Member
461 Points
540 Posts
Re: XMLHttpRequest question
Jan 16, 2012 11:07 AM|LINK
Hmmm,
Now I am really worried...
shtrudel
Member
461 Points
540 Posts
Re: XMLHttpRequest question
Jan 16, 2012 11:16 AM|LINK
Don't you get Runtime Error ?
What do you get in the xmlhttp variable when debugging ?
san SanZ
Member
296 Points
60 Posts
Re: XMLHttpRequest question
Jan 16, 2012 11:23 AM|LINK
hey im sorry,
i tesetd in c# working fine,vb im checking now
problem with responsetext contains "\n\r" which is not allowing to set to div
-- If you find this post helpful then please "Mark As Answer"
san SanZ
Member
296 Points
60 Posts
Re: XMLHttpRequest question
Jan 16, 2012 11:32 AM|LINK
i got the problem,
but i dont know exact reason
if we comment Response.Write in code behind it started workin
-- If you find this post helpful then please "Mark As Answer"
shtrudel
Member
461 Points
540 Posts
Re: XMLHttpRequest question
Jan 16, 2012 11:39 AM|LINK
Not working for me even if I comment the Response.write...
Thanks for your effort
BU XI - MSFT
All-Star
22367 Points
2704 Posts
Microsoft
Re: XMLHttpRequest question
Jan 18, 2012 03:00 AM|LINK
Hello
As you are in the Page_Load event, so the full page's content is returned to the user.
For an AJAX request, you may try Render event to output the response content.
For example
protected override void Render(HtmlTextWriter output)
{
output.Write("Hello World");
}
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
shtrudel
Member
461 Points
540 Posts
Re: XMLHttpRequest question
Jan 18, 2012 08:37 AM|LINK
THANK YOU !