• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ajax and servlet problem

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to build a web application based on jsp ,ajax and servlets.The idea is to create a jsp that contains some options available for that user(previously he has to log in) and put a link on them.When the user clicks one of these links a xmlHttpRequest is send to the servlet informing it about this event ,the servlet performs some operations, and replys back.In the onreadystatechange I check this reply and if it is the expected one, I have to delete that link. The problem is that what ever I do ,the responseText comes back containing the html from the page that sent the request. What is it wrong ?






and the part in servlet where I respond to the request:
if (comanda.equals("register"))
{
int id=Integer.parseInt(request.getParameter("id"));
response.setContentType("text/html");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().println("true");
}

previously I store some data in the session.
[ November 23, 2008: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure that your Ajax request is correct and causing the servlet to execute as you think it is?
 
nik klaus
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes ! everything woks fine until I try to use the responseText
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At this point, I'm going to move this over to the JavaScript forum as the problem is unlikely on the server.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Time to post your client-side code.
 
nik klaus
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ November 23, 2008: Message edited by: nik klaus ]
 
nik klaus
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://myfreefilehosting.com/f/e8de0128ef_2.93MB
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One problem with your code is that the returned message might not just be true -- it's more likely to be something like \n\ntrue\n

You should use a method like indexOf on the string to see if "true" is present somewhere in the returned text (of course, this is risky, since there is some slight change that the word "true" will appear in a generated error page with a stack trace, so it's usually best to come up with something a lot more complex that is unlikely to show up in the response accidentally)

If you did something like an alert(responseText) and saw that you are getting the html code for this page, then it seems likely that you are actually just re-requesting the same page.
 
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic