This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
So, you aren't using Servlets, you are using Spring MVC, which has Controllers.
Have you tried to step through the serverside code to see if it is even getting to the first line of code?
Have you tried to get to it via the URL directly in the browser to see if it gets to the server side code?
This will tell us if you are using the correct URL to access the method.
If it is getting into the code, you are returning the data into the body. Do you have the jackson jar file in your classpath? Are you also setting the response status to successful with @ResponseStatus(HttpStatus.SOMETHINGINTHEENUM) on top of that method?
Are you familiar with all the annotations Spring uses in the Spring RESTful Web Service module?
Also, like I said if I hit the URL in a browser, the browser prompts me to download "application/json" data (it's in the latter half of my original post).
If it matters, I've tried hosting the webapp on Tomcat 6 and Weblogic 9.2 with the same results.
I've been fighting this for 2 days now with no success. If you happen to figure out what the problem is, please post the solution.
It certainly looks like a jQuery issue as the browser is detecting json correctly.
Joined: Aug 25, 2010
Sorry I meant the URL does work in the browser; it prompts me to download application/json data. I agree with Zaq; this might be an issue with jQuery. However, like I said, I've tried different versions with no success.
Joined: May 10, 2011
I *think* I finally figured this out. For my situation at least, I was simply using an html file to test rather than serving it in the same container as the app. That makes the browser treat it as a cross-domain request. Cross-domain means JSON is no good and thus, you don't see the response come back.
When I put the same file into the app (served by the same container), it worked fine and I could see the response JSON.
Hope that helps.
Joined: Aug 25, 2010
Hi Zaq, I've been doing things the same way you have (just an html for testing) and so, with great haste and fingers crossed, I will try your solution.
Edit: It worked!
Thanks for all the help guys. I hope this thread helps somebody else in the future. Though I'm still baffled why passing data around with json on cross-domain requests doesn't work.