File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion 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

AJAX response to a Restful Jersey Resource

Trilochan Bharadwaj
Ranch Hand

Joined: Feb 02, 2009
Posts: 100

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?


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: 15302

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 ...


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:
subject: AJAX response to a Restful Jersey Resource
jQuery in Action, 3rd edition