aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Passing a json object from servlet 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 "Passing a json object from servlet" Watch "Passing a json object from servlet" New topic
Author

Passing a json object from servlet

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
So i am using a jquery library for form validation and no matter how i send the response I always get an ajax parse error.
According to the manual of the library i should send an array the exact words of the documentation is


Now my servlet sends this



I have also noted that in the ajax

Then the success callback of $.ajax is called other wise the error one is called.

Could anyone please tell me why i ma getting the parseerror here ??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

You are not sending valid JSON. The "arr=" prefix and the trailing semicolon are not valid. You are sending a JavaScript statement rather than a JSON construct.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
I also tried this and that didnt work as well. Any tips on how to get it rite??
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

Since that's identical to what you first tried, which didn't work, it's not surprising that it didn't work.

Have you considered taking Bear's points into account?
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
just corrected a typo
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

You still seem to be under the assumption that JSON == JavaScript.

Not so.

Just because you can use single quotes to delimit a string in JavaScript, does not mean you can do the same in JSON.

Visit json.org. Learn it. Love it.
 
jQuery in Action, 2nd edition
 
subject: Passing a json object from servlet