This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

.getJSON not returning any response.

 
Gopi Chand Maddula
Ranch Hand
Posts: 40
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi JavaRanch,

I recently came to know that there is a process of data exchange which is light-weighted called as JSON objects. I feel interested and tried to implement it using JSON objects.

My example calls a serverside jsp which will return a JSON object. But the callback function in the .getJSON method is not working. Please help me resolving this issue.

The serverside jsp is--service.jsp


the above jsp returns just JSON object, and if i try to execute the jsp in the browser the response is as follows.


but when i try to get the JSON object using jquery's $.getJSON method its not giving any response.



you can see some debugging alerts as well in my example. But the alert in the callback function isn't getting executed. And for your info the server side jsp is executing for sure.


Can somebody assist me rectifying the errors i have made.

Thanks in Advance.


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using a JSP to generate the JSON is a major problem. Use a servlet instead.

But the primary issue is that you are not returning a JSON representation -- you've got a lot of other crap in there as well, such as the DOCTYPE decalration.

If you return bad JSON, the callback will not be called.
 
Gopi Chand Maddula
Ranch Hand
Posts: 40
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Using a JSP to generate the JSON is a major problem. Use a servlet instead.


Thanks for your Reply.

Yes as per your suggestion i changed jsp and declared as servlet.

Below is the servlet is had written.



and when i run the following script, to my surprise the servlet thrown a weird errortrace which is



As it clearly states that org.apache.log4j.Category class is missing, i verified my log4j-1.2.16.jar and it contains the mentioned class.

Just for debugging i thought of removing the log4j jar and run, i did it and it executed correctly. and given response correctly.
But for my project the log4j-1.2.16.jar is mandatory for logging.

I am little bit confused with the jars that are required for using json. In a example i saw that the required jars are.
commons-lang 2.3
commons-beanutils 1.7.0
commons-collections 3.2
commons-logging 1.1
ezmorph 1.0.4.jar
json-lib-2.2.2-jdk15.jar

I added all those jars and as i said early my project requires log4j as well.
so the WEB-INF/lib folder contains all the list of jars mentioned along with log4j-1.2.16.jar.
But it json isn't working if i have log4j.jar in my lib folder.


Am i doing any mistake or please let me know the procedure which is greatly appreciated.
 
Gopi Chand Maddula
Ranch Hand
Posts: 40
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mentioned earlier that my code is working fine when log4j is removed from my project,
but as log4j is important i am still debugging the issue.

Meanwhile i want try my code with the another URL rather than using my example which returns JSON object,
But there is no response in this scenario as well.

what are the changes i should need to do, so that i can access the outside URL which returns JSON Object.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The required jar files are missing from your web app. Add them to WEB-INF/lib.
 
Gopi Chand Maddula
Ranch Hand
Posts: 40
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:The required jar files are missing from your web app. Add them to WEB-INF/lib.


I have already added all required jars and still showing the error.
But i tried to add commons-logging.jar as well and then it worked fine for me.

As it is working fine with my example i tried to use the same for the cross domain url which returns a json object.
Still my struggle goes on. its working for my sample but not for the cross domain Url.
I think there is a problem in forwarding data to the crossdomain url using $.getJSON() Method.

Am i doing anything wrong which doesn't work for cross domain URL

Thanks in advance......
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic