aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes .getJSON not returning any response. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark ".getJSON not returning any response." Watch ".getJSON not returning any response." New topic
Author

.getJSON not returning any response.

Gopi Chand Maddula
Ranch Hand

Joined: May 11, 2010
Posts: 40

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

Joined: Jan 10, 2002
Posts: 60992
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gopi Chand Maddula
Ranch Hand

Joined: May 11, 2010
Posts: 40

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

Joined: May 11, 2010
Posts: 40

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

Joined: Jan 10, 2002
Posts: 60992
    
  65

The required jar files are missing from your web app. Add them to WEB-INF/lib.
Gopi Chand Maddula
Ranch Hand

Joined: May 11, 2010
Posts: 40

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

Joined: Jan 10, 2002
Posts: 60992
    
  65

Same origin policy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: .getJSON not returning any response.