• 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

Head Rush Ajax and JSON

 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a whole chapter on JSON and XML.
I'd like to ask how popular JSON is, and how far did you explain it in the book.
Thank you.
 
author
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have mixed feelings about JSON, to be honest. I don't particularly love it as a data format for Ajax, because I don't feel it's that readable. It's arguably less verbose -- and therefore, also in theory, faster to send across the network -- than XML, but marginally so. And I don't think it's very intuitive.
That said, there are a ton of people who really like JSON, and I'm not religious about what data format you use, so it's covered. In fact, I really treat it in the book as a competitor to XML (they have a boxing match, so to speak), and compare and contrast them heavily.
In terms of depth of coverage, I think you'll find that once you get the basics on how JSON looks and is formatted (which is covered), it's a piece of cake. So I think most people looking for anything but the most extreme, advanced, unusual use-cases for JSON will find everything they need for JSON in the book.
But then again, I'm biased :-)

Thanks
Brett
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brett, if I may, I'll add my $0.02 on the JSON vs. XML title bout.
I think the place where JSON is the most useful is if your JavaScript application is creating a lot of objects to hold the application's data. Sending the data in a format that is essentially already JavaScript would save much parsing of XML.

I think the down-side is not on the browser with its JavaScript, but on the server-side, especially if, like our enterprise application, the web-tier communicates with our back-end server, which does most of the "heavy lifting" even for our Eclipse Rich Client desktop client and that server in turn retrieves data from any one of several RDBMS servers. That is just way too much heavy XML zapping back and forth to expect to change it all into JSON just for the web-based client, when we can use the exact same XML as we would send to the desktop app.

JSON is interesting and I may end up using it a lot on my own web site and some of the sites that I do pro bono for local non-profits, but I think JSON's utility in the enterprise stack is quite limited.
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it has a lot discussion on ajax response, pls check here

 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have mixed feelings about JSON, to be honest. I don't particularly love it as a data format for Ajax, because I don't feel it's that readable. It's arguably less verbose -- and therefore, also in theory, faster to send across the network -- than XML, but marginally so. And I don't think it's very intuitive.



Hello Brett,
Nice to have you here in JR. Question - why is readability important becasue we extract the data and display it on the screen?
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How does the server create the JSON response object? Some AJAX framework sends the response ?
 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ajax is used for handling the response from the server.

If the server response header has a content-type of "text/plain" you have to use the responseText property to retrieve the response data.

If the server response header has a content-type of "text/xml" then the XMLHttpRequest parsed XML data available through responseXML property.

If the server side service(or jsp/asp/php/cgi etc) sends a JSON response it will be in the JSON format which will have a content-type response header of "text/plain", hence it will need to be retrieved using the responseText property.

Parsing the JSON response is much easier then parsing the XML response, thats one difference between then two reponses.

Regarding sending the JSON response from the server side, there are frameworks available which can create JSON from data which can be then readily sent to the response.

I hope this helps.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradip bp:
How does the server create the JSON response object? Some AJAX framework sends the response ?



The very basic idea behind it is:

You have to create the JavaScript code on the server. Just like how you would create any dynamic string. Loop through your results and build the object.

When you get the responseText back, it is evaluated with eval method and you have the JavaScript object.

Just search Google for JSON tutorial and you can find a lot of information.

There is a project called BadgerFish that does the translation from XML to JSON for you. See this: http://ajaxian.com/archives/badgerfish-translating-xml-to-json

Eric
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic