Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AJAX Problem in responseText

 
Saptarshi Chakraborty
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,
I'm new to Ajax programing.I have written a code in ajax in a jsp page but somehow
httpReq.responseText is returning the entire page.That means alert(httpReq.responseText) is returning the whole html code.Please someone help me to get a solution for this .
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SAPTARSHI CHAKRABORTY, please do us all a favor and modify your display name to not use all uppercase. It's very hard to read. Our eyes will thank you!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reponse will contain whatever gets written to it. If your Ajax request hits a server-side resource that returns an entire page, that's what responseText will contain.

Be sure that your request is only setting what you want set into the response.
[ November 01, 2007: Message edited by: Bear Bibeault ]
 
cathymala louis
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do have the same problem. The reponse I got is whole html page not the time what I want. I am really new to ajax. This is my first sample program. Could you please some one point me to the good tutorials.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you requesting? Your server resource can deliver just what you want it to. I don't really understand the problem. If you don't want it to return an HTML page, don't give it the URL of the HTML page.
 
cathymala louis
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my html page code.

xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{

document.myForm.time.value=xmlHttp.responseText;

}
}
xmlHttp.open("GET","time.jsp",true);
xmlHttp.send(null);
}

This is my jsp code

<%Calendar currDateTemp = Calendar.getInstance();

int currDD1=currDateTemp.get(Calendar.DATE);%>


<% response.getWriter().write(currDD1);%>

Could you please let me know what I am doing wrong. I don't have any clue.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and most people will just go elsewhere. Please read this for more information.

You can go back and change your post ot add code tags by clicking the .
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that all that's in your JSP? If it is, then there is no way that that JSP can render a complete HTML page. Why do you think that it does?
 
cathymala louis
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry, my complete html page is


The ok bolded in the jsp is nothing but onkeyup. The website stopping me to post onkeyup.

my complete time.jsp code is




while i start type some thing in the text box i am getting the whole time.jsp content excluding the java commands.
[ November 09, 2007: Message edited by: cathymala louis ]
[ November 09, 2007: Message edited by: cathymala louis ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ask again, if you don't want HTML markup returned as the response why are you putting it in the JSP?
 
nik klaus
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
</script>
</head>
<body>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic