• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Ajax responseXML problem

 
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I was going through "Head first Ajax". There in chapter 2, we are having a registration page. Once we enter username field we make a check thorough ajax request object.

The flow is somewhat as below
registration.html--->javascript(var url = "checkName.php?username=" + username;)--->checkName.php.

Now in our checkName.php we are creating an array, and checking the parameter send by request URL againt it as below-:



where as in our javascript we are looking for the response as-:


Now this is fine with php as response from server will be just "Okay" or "denied". But as i dont know php am using a Jsp in place of it as shown-:


and my javascript as-:


But now the problem is that unlike php response of just "okay" or "denied" i shall be getting full jsp as a response with "exists" in body tag if user exists.
so this can't match the condition i have written in my javascript (request.responseText!= "exists").
Is there a way to overcome this? Using request.responseXML instead of request.responseText ?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are getting the full response because that is what you are sending down to the page.

You probably want to call a servlet instead of a jsp.

Eric
 
Sheriff
Posts: 67650
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
It's fine to use JSP. Remember a JSP does not have to be a full HTML page. It can be whatever fragment of text you want it to be.
 
Pranav Bhatt
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to use request.responseXML.document.getElementById("show"). But this not working too. Below was the JSP page
 
Bear Bibeault
Sheriff
Posts: 67650
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
What is it you are trying to get from the JSP? If all you need is some simple text, why do you have all that other crap like <body> in there?
 
Pranav Bhatt
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,
Even if i remove the body and html tags still i need the import tag for JSTL. And the logic to search name in my array as below-:


I tried to capture the output to request.responseText through alert and it shows exists but have line spacing preceding and following it.
For test i removed all logic and just wrote exist in jsp then it works fine . But still i have to go through the loop to search the user or else will have to change the code somewhat if we cant have just exists as response from this JSP.
 
Pranav Bhatt
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey well i got a idea. Trim the whitespace before and after the string. It worked now-:



and the trim function as-:


Thanks to all for help. Bear thanks for giving the idea of removing all tags
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic