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

 
Industry : Internet Functional Area : Programming Languages
Activity:  1 comments  483 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
ASP.Net, VB.NET, SQL Server, Software Developer, Dhruv
Job Openings for Linux,File Server Developers.
Job Openings for Websphere Commerce, Bangalore
Viewers also viewed
yes , it will decrease vs no it wont effect the speed
 
430 referals 43 arguments, 1192 views
Obviously there is never a winner in “language X is better/faster/more scalable than language...
 
3 referals 33 arguments, 53357 views
There is many people around us who do not the know the power of internet. They either give out...
 
2222 referals 19 arguments, 384 views
more...  
Recent Knowledge (56)
10 things about good bosses   Do you like your boss? Let's be honest, a majority of employees...
 
0 referals 2 comments, 125 views
India is a free nation. People have rights but still women are struggling to come up. There is a...
 
0 referals 6 comments, 73 views
My friend Rizwan Khan mailed me this interesting draft made by a Pakis journalist.   Written by...
 
427 referals 42 comments, 2675 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...