JSON is a subset of the JavaScript that provides a fairly terse, dense data notation. When passed as data client-side it can be deserialized into a JavaScript Object with one line of code. In contrast XML is bulky and requires a fair bit of code client-side to parse and work with it. I believe that the denser notation and client side ease of use make JSON a ideal data transfer format for AJAX.
Lets take a quick look at some data in both XML and JSON formats...
XML:
<Table>
<Rows>
<Row><Item>1.1</Item><Item>1.2</Item></Row>
<Row><Item>2.1</Item><Item>2.2</Item></Row>
</Rows>
</Table>
JSON:
{Rows:[{Item:[1.1,1.2]}{Item:[2.1,2.2]}]}
The leaner format can cut the size of your data in half and while you do loose a bit of the human readability with JSON, you can always use a tool like Charles to break it out into a tree view when debugging. The real beauty of JSON, however, is the ease of working with it on the client. If you deserialized the data into a variable called DataTable you can read first item in the second row by doing this:
DataTable .Rows[1].Item[0];
The trade off is that you will get cleaner, smaller client side code in exchange for more work getting your data into JSON on the server. Personally I would rather have the extra code on the server where it can be unit tested and easily debugged than on the client where it can .
Some might say that if you aren using XML then you aren doing AJAX. I disagree. I think that AJAX is actually a misnomer and so is the XMLHttpRequest object that it uses. XMLHttpRequest doesn require that your data be in XML and will accept any format you choose. Believe it or not even JavaScript isn even required to do AJAX; I hear VBScript works with XMLHttpRequest just fine.
I think that we have missed the big picture; JavaScript and XML aren the reason why AJAX is such a phenomenal tool... it is the Asynchronous HTTP requests that it provides that make it so powerful. Also DOM scripting and DHTML are not AJAX, although they are used quite effectively in conjunction with it to provide the rich features that everyone associates with AJAX. The bottom line is that any site that makes Asynchronous HTTP requests is using AJAX and any site that doesn , isn .
The irony is that the one technology that is actually required for AJAX, HTTP, isn even in the name. I think that AJAX would be better called Asynchronous HTTP-Request Scripting. Sadly AHS will never have the marketing appeal of the cool sounding AJAX, so we are stuck. As for the purists out there, I am sure you would prefer that I say that I am recommending "Asynchronous HTTP request scripting with JavaScript and JSON" than for me to talk about using JSON with AJAX. Sorry no such luck.
source: coderenaissance
Related Stuff
-
MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.
-
Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone
-
TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support
-
ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.
-
Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.
-
Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software
- PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.
Be the first ... |Add your comment.
Your Comment ...
Name (required)
Email (required, hidden)
Website
