• 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 response to a Restful Jersey Resource

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Trilochan Bharadwaj
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic