This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes AJAX response to a Restful Jersey Resource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "AJAX response to a Restful Jersey Resource" Watch "AJAX response to a Restful Jersey Resource" New topic
Author

AJAX response to a Restful Jersey Resource

Trilochan Bharadwaj
Ranch Hand

Joined: Feb 02, 2009
Posts: 100
Hi,

I have an AJAX client which retrieves a simple string literal (at least tries to) response from a Restful Resource on the server, using a simple Java Client I can see the response OK and do anything with it; But when I use AJAX to retrieve response, the status comes as 0 for XMLHttpRequest Object, despite the fact that readyState value is set to 4. Below is my JS client code:


My Restful resource uses Jersey RS implementation, Here's the code for my Resource:


I built a TestNG test case for the same, using simple client code:

^^ The above java code gives response : 200 ... But in case of AJAX client, I get blank response text, When i check status value it is set to '0', but readyState = 4. Please note that I have to use Native AJAX stuff for this, cannot rely on any third party libraries to make AJAX calls (JQuery, Prototype, Dojo et. al.) unfortunately

Any pointers as to where I am doing something wrong?

Trilochan.

Addendum : In case of an AJAX request,

prints on the server, which means the request goes through ... but no response
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Wow, that JavaScript code looks scary. Having no clue about what library you are using there, it's going to be difficult to decipher and debug. On a side but related note, your entire JavaScript code could be condensed to the following using JQuery:



Isn't that super cool?


GenRocket - Experts at Building Test Data
Trilochan Bharadwaj
Ranch Hand

Joined: Feb 02, 2009
Posts: 100
Hey Greg,
Thanks for your reply. OK, maybe I over did my log thingie it just helps me debug on firebug better. If you read my entire post though, at the end, I do mention that I can't use, JQuery, Dojo, Prototype, DWR, Moo Tools ... well you get the picture ;)

I understand that there are frameworks that do this kinda thing and condense the code into few lines ...

Trilochan.

Addendum: This is not any third party library, it forms part of an open source framework that I am building and working on, here's the link:
HCIS framework
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AJAX response to a Restful Jersey Resource
 
Similar Threads
Sequence of steps executed in Ajax call
Problems sending and receiving with XMLHttpRequest
Browser Redirection and Ajax
Javascript on Demand
How many times onreadystatechange property of XMLHTTPREQUEST would be get called?