• 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

.getJSON not returning any response.

 
Ranch Hand
Posts: 41
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Same origin policy
 
Something must be done about this. Let's start by reading this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic