| Author |
Ajax responseXML problem
|
Pranav Bhatt
Ranch Hand
Joined: Mar 20, 2006
Posts: 283
|
|
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 ?
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15362
|
|
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
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56554
|
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Pranav Bhatt
Ranch Hand
Joined: Mar 20, 2006
Posts: 283
|
|
I tried to use request.responseXML.document.getElementById("show"). But this not working too. Below was the JSP page
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56554
|
|
|
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
Joined: Mar 20, 2006
Posts: 283
|
|
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
Joined: Mar 20, 2006
Posts: 283
|
|
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
|
 |
 |
|
|
subject: Ajax responseXML problem
|
|
|