File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes AJAX Problem in responseText Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "AJAX Problem in responseText" Watch "AJAX Problem in responseText" New topic
Author

AJAX Problem in responseText

Saptarshi Chakraborty
Greenhorn

Joined: Jul 26, 2007
Posts: 23
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

Joined: Jan 10, 2002
Posts: 61623
    
  67

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!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

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

Joined: Nov 02, 2005
Posts: 77
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

Joined: Jan 10, 2002
Posts: 61623
    
  67

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

Joined: Nov 02, 2005
Posts: 77
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

Joined: Jan 10, 2002
Posts: 61623
    
  67

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

Joined: Jan 10, 2002
Posts: 61623
    
  67

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

Joined: Nov 02, 2005
Posts: 77
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

Joined: Jan 10, 2002
Posts: 61623
    
  67

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

Joined: Nov 23, 2008
Posts: 8
</script>
</head>
<body>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AJAX Problem in responseText