Johnny Chan

Greenhorn
+ Follow
since Mar 05, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Johnny Chan

Actually i did:


but i see it doesn't take into account the situation where jsonData doesn't exist.
Okay, yep, needed to set:


and now its working. thanks very much. i assume i'll need to alter the javascript line


to account for the change to the structure.
If i do that, then i get a "not well-formed" error,



where the arrow is between the " and v.


So the response here is:


and the syntax error is pointing to the {" in characters 2 - 3.
I've tried to do that, but then i get something like:



and it still gives a syntax error because i think "values" is in quotes. So perhaps it is how i am creating the jsonobject using json-lib that is incorrect.
Yes, its the only thing being returned by the server.
the main page calls getCBParameter,


I'm using java servlet to send back JSON data to client side javascript. I build a JSONArray of string values using json-lib and it is received and is even parsed by my javascript, but in the firefox error console i get a syntax error:

["A","B","C"]

and the arrow points to between the " and the A. Any idea what is causing this?

thanks-jc
Okay, yup, i was getting a 404 error because i referring to /TestServlet, instead of /app/TestServlet. That's why i'm a greenhorn! Thanks for your help. One other question. If i'm accessing a potentially large dataset in the servlet that is in a mysql database, is JSON the preferred method or is it XML? I just wanted to gauge your thoughts on the matter.

-JC
Okay, I had only enabled "script" for debugging in firebug. I see what you were referring to.
I'm not sure where i find that in firebugs. I can tell you that the function "success" in the ajax() function of jquery does not appear to be run.

I am not using XML though, i am using JSON.

Edit:

I see that jquery getJSON function should return XMLHttpRequest, but i don't see that in firebugs. I will look.
I added that into the servlet code, and same result. I recall trying something similar, but not using flush. json variable is still null.
Same result, json is null according to firebugs. It never even gets into the function(json). After .getJSON returns and presumably has called the servlet, and its about to call function(json), json is null and the next step is out of the execution.

I do get 1 error in the error console,

window.console is undefined
http://localhost:8080/test Line 47.. of which there is none. I'm not sure this has any bearing on the problem though.
I'm trying to get data back from a servlet in JSON format. I am using jquery, and have written a simple test just to return some data and then alert me of it in an html page. However, everytime i reload the page, the value of the data passed back from the servlet is null. If i access the servlet directly, i can see the data posted to the screen.

Here is my webpage's code:


Firebugs tells me the parameter "json" is null.

And here is my servlet code:


As I said, when i go to: http://localhost:8080/TestServlet I see:
{"optionValue":"1","optionDisplay":"2009"}

in text - which is i believe what i want. I've used cactus on the servlet as a test, and it returns the json data, but is it formatted correctly? Am i somehow now sending it back in good format for jQuery? Your ideas are welcomed.

-Johnny