Build your professional network on facebook via our app Go to app
 
<< Prev  4 of 4 in Topic 
Posted in Community :

Web Technologies |

Patni Computer Systems

 
By : Ujwal Chana, Project Lead, Polaris Software
Industry : Internet Functional Area : Programming Languages
Activity:  1 comments  627 views  last activity : 07 06 2010 20:18:04 +0000
 Refer 10
Share
 
 
 

When Microsoft added the ActiveX XMLHTTP object to Internet Explorer's implementation of JavaScript, the company planted the seed for the revolution in Web applications known as Asynchronous JavaScript and XML, or AJAX. Today, Firefox, Safari, Opera, and other browsers all support what is now known as XMLHttpRequest, making possible sites such as colr.org, backpackit.com, and maps.google.com. These and other sites feature applications that act and feel like other desktop applications—even though they're running in a browser.

In AJAX, the JavaScript on the page sends requests to a Web server for data while the user's viewing and interacting with the page (hence the "asynchronous" part of AJAX). Those requests are HTTP requests just like the one the browser used to retrieve the page in the first place, as well as any images, stylesheets, and so forth. As such, the XMLHttpRequest object can be used to retrieve any kind of data, not just XML. For example, JavaScript can use XMLHttpRequest to retrieve a plain text file from a Web server and display its contents within a form.

The XMLHttpRequest object analyzes the MIME type of the data coming back from the Web server by looking at the Content-type header that precedes the data. If it's text/plain for example, you can access the text by examining the XMLHttpRequest object's responseText property. But, if it's text/xml, the XMLHttpRequest object takes an extra step: It runs an XML parser on the returned document and builds a Document Object Model (DOM) tree in memory representing the document, and makes that available in the responseXML property. You then can use JavaScript's standard DOM methods to navigate the tree and retrieve elements, attributes, and other text occurring in the tree.

XML is the standard way to interchange data, but it's often not the best way. Although XML can add structure and metadata to data, it does so in an overly verbose way. XML also has a fairly complex syntax, requiring a non-trivial parser to attack it. In JavaScript, XML must be parsed into a DOM tree to be used. And, once you've constructed the DOM tree, you still have to pilot through it to create corresponding JavaScript objects or otherwise use the XML data in your client-side Web application.

Fortunately, there's a better way.

Welcome to JSON

The JavaScript Object Notation, or JSON, is a lightweight syntax for representing data. JSON's elegance comes from the fact that it's a subset of the JavaScript language itself. You'll see why that's important later. First, compare the raw syntax of JSON against XML.

Both XML and JSON use structured approaches to mark up data.

By using this technique, your JSON files always start with an object with a single named property that identifies the "kind" of the object.

If you're watching closely, you might've noticed that the XML version at least states up front what object is contained in the document with the root document element.

This is absent in the JSON version. Why? Presumably, if you're developing JavaScript that accesses a Web service, you already know what you're going to get back.

 

 
TrackBack URL:
1 comments on "Speeding Up AJAX with JSON"
  Commented by  Dipak Mawale, Senior Executive, Harbinger Knowledge Products    | 06 13 2008 14:11:06 +0000
Thanks for sharing this with us
Add your comment on "Speeding Up AJAX with JSON"

Rate:
Submit
Leading Recruitment Firm
Leading Recruitment Firm
Viewers also viewed
Hi All, How is the idea of moving from .net Development to Java development sound to you? One of...
 
181 referals 22 arguments, 933 views
You succeed based on the quality of your work, the amount of work we can do and one other...
 
241 referals 5 votes, 251 views
Obviously there is never a winner in “language X is better/faster/more scalable than language...
 
3 referals 34 arguments, 73628 views
more...  
Recent Knowledge (14)
What could be the size of Indian Switch market ( Low Voltage)
4 referals 15 comments, 526 views
A 28 year old, Divya Narendra, son of an Indian immigrant doctor couple in the U.S., has moved...
 
192 referals 24 comments, 5526 views
It is relatively easy to identify the use count and resource usage of your SP’s, but first let...
244 referals 6 comments, 401 views
more...  
More From Author
Yes infact this software aided prescribing will improve prescription, as soon as the doctor enters the drug, he will be getting all those conditions about the patient and the stages of the infection or the disease, so with that data he can precisely...
Was gmail crash on 24th feb 2009 for three hours a mishap or a trick from hackers?
An accounting error reportedly led Microsoft Corp to notify some laid off employees last week that they would need to give back part of their severance pay. The world's largest software maker laid off 1,400 workers last month, the first of...
more...