Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Empty answer when trying to get JSON from Jersey Server  RSS feed

 
Soeren Liebich
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I try to build a RESTfull webservice.
On the backend I use a Jersey Server. On the Frontend I want to get the data with jQuery using ajax methods.
I took the example from http://www.mkyong.com/webservices/jax-rs/json-example-with-jersey-jackson/ and tried to get the Data with $.getJSON and $.GET.

The problem is, that I always can't access the response data. Also jQuery always only executes the fail method.
After that I tried it with a simple servlet. With that I get the same result.

Does somebody know what I am doing wrong or how I can make this stuff working?

The project is deployed on a Tomcat 7.

Greetings from Germany
Sören

Code:

index.html


Servlet:

JSONServlet.java


web.xml


Jersey

Track.java


JSONService


web.xml
 
Soeren Liebich
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to Stackoverflow I was able to find the solution of my problem.

The problem is, that I use a cross request and I have to add "Access-Control-Allow-Origin: *" to the response header.
With this information I found http://blog.usul.org/cors-compliant-rest-api-with-jersey-and-containerresponsefilter/.

With the solution described there, the success method is executed

Greetings from Germany
Sören
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!