• 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

jQuery getJSON question

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on an HTML page which is using jQuery's getJSON method to call another web application (different domain entirely).

The servlet in this other web app will get the request and return a JSON object indicating success or failure. So in my servlet I write to the output stream gotten from the response:



and then in my javascript which called the servlet:





The problem is that when I execute the JS I am seeing an error "Invalid label" in firebug.

I know jQuery works as I was able to make their example code run right out of the box. So I am thinking it must be something wrong with what I am writing to the output?

Any help would be appreciated.

Thanks,
Seamus
 
Sheriff
Posts: 67747
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
Please take the time to choose the correct forum for your posts. This forum is for questions on advance Java.

This post has been moved to a more appropriate forum.
 
Bear Bibeault
Sheriff
Posts: 67747
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

Originally posted by Seamus Minogue:


That can't possibly be your actual code as that won't compile. When posting it's important to show real code without mistakes, otherwise everyone's time, including your own, is wasted. Please read this for more information.

It's likely that your JSON is not properly formatted. But we need to see the real code before we can say for sure.
[ July 24, 2008: Message edited by: Bear Bibeault ]
 
Seamus Minogue
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I wasnt sure which forum would be most appropriate so I guessed at the advanced.

Because its about Java, Servlets, HTML, Javascript... Thanks for moving it.

You're right thats not my code I screwed up while typing:




I put in some extra quotes while I was typing it :-(
 
Bear Bibeault
Sheriff
Posts: 67747
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
Please take more care when posting. Enough posts like that and people learn to avoid your questions.

Now, onto your issue. That error usually crops up when the JSON is malformed. Are you sure that you're setting it into the response correctly?

I set up the following test page:

where the file json.data contains:

and everything works fine.

Make sure that your response contains what you really think it does. The Firebug plugin for Firefox can show you exactly what is going on with your Ajax call, including the response body.
[ July 25, 2008: Message edited by: Bear Bibeault ]
 
Seamus Minogue
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear :-)

Was the end of the day and I was sloppy when I typed in the example code.

Also thanks for your response. I actually found the answer on my own and like you were saying it had to do with what I was returning.

Thought I would post the code from my servlet incase anyone else down the road runs into this like I did.

This is the doGet method from my test servlet which will handle the jQuery.getJSON request. It is making use of the JSONObject although it would be possible to just create the string on your own if you were so inclined.




Thanks again for the help :-)
[ July 25, 2008: Message edited by: Seamus Minogue ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic