Javascript Basics Part 10

You've probably heard the term 'AJAX' thrown around recently. Over the past year or so, AJAX-style JavaScript has become increasingly popular among many developers. In this 10th article in our JavaScript Basics series, we will introduce you to AJAX and show you how you can use this technology!

provided by: 
Originally published at Internet.com


You've probably heard the term "AJAX" thrown around recently. Basically it's a fancy name for a technology that's been around for years. Over the past year or so, however, AJAX-style JavaScript has become increasingly popular among many developers and we're starting to see some amazing things come from it. Google Maps and GMail are two of the most well known AJAX applications, but companies all over the web are starting to incorporate it into their sites. AJAX stands for Asynchronous JavaScript And XML. All it really consists of is JavaScript, just like you would have in any other application, and an XMLHTTP connection to your web server. That's it! The general idea is that when you need to pull data from a server you can just go and get the specific data you need instead of refreshing the entire page. To start with, AJAX almost always relies on a server-side language such as PHP or ASP. When your users need to get new data, the JavaScript requests it, and the server will probably query a database and then return the data. This data can be returned in several forms. If it is structured, then you will generally have XML or JSON data. If it is very simple data (such as getting a description for an item), you will often see people just writing that data directly to the AJAX response. Creating an XMLHttp Object The first thing we need to do when creating an AJAX request is to create an XMLHTTP object. Netscape/Firefox, Opera and other browsers have this object built-in. Internet Explorer uses an ActiveXObject. So we create one function that works for all of these browsers: if(typeof(XMLHttpRequest)!='undefined'){ var getXMLHttpObj = function(){ return new XMLHttpRequest(); } } else { var getXMLHttpObj = function(){ var activeXObjects = ['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP']; for(var i=0; i JSON: {contacts:[ {"firstname":"Joe", "lastname":"Smith", "phone":"555-1212"}, {"firstname":"Sam", "lastname":"Stevens", "phone":"123-4567"} ]} You may notice that the XML notation looks suspiciously like HTML. Well for the most part, it is. HTML and XML are both tag-based languages and they can even be parsed the same way (see the 6th article in this series for more information). Further, the JSON notation looks suspiciously like plain ordinary JavaScript. JSON stands for JavaScript Object Notation and as such it is just plain ordinary JavaScript. Either notation can just be sent as plain text from your web server. None of the spacing included in these examples is necessary except for the single spaces

Author: Mark Kahn

Read article at Internet.com site
Related Articles
- Javascript Basics Part 5
Up until now we have been focusing on the language constructs of JavaScript: if statements, loops, functions, etc. In this primer we are going to take a step back and cover the inner workings of some of the native JavaScript objects: Strings, Numbers and Arrays.
- JavaScript Basics Part 2
- Javascript Basics Part 6
- Javascript Basics Part 11
- Javascript Basics Part 7
- JavaScript Basics Part 1
- Javascript Basics Part 12
- Javascript Basics Part 9
- Javascript Basics Part 3
- Javascript Basics Part 4
Regional Articles
- Javascript Basics Part 10 Alabama
- Javascript Basics Part 10 Alaska
- Javascript Basics Part 10 Arizona
- Javascript Basics Part 10 Arkansas
- Javascript Basics Part 10 California
- Javascript Basics Part 10 Colorado
- Javascript Basics Part 10 Connecticut
- Javascript Basics Part 10 DC
- Javascript Basics Part 10 Delaware
- Javascript Basics Part 10 Florida
- Javascript Basics Part 10 Georgia
- Javascript Basics Part 10 Hawaii
- Javascript Basics Part 10 Idaho
- Javascript Basics Part 10 Illinois
- Javascript Basics Part 10 Indiana
- Javascript Basics Part 10 Iowa
- Javascript Basics Part 10 Kansas
- Javascript Basics Part 10 Kentucky
- Javascript Basics Part 10 Louisiana
- Javascript Basics Part 10 Maine
- Javascript Basics Part 10 Maryland
- Javascript Basics Part 10 Massachusetts
- Javascript Basics Part 10 Michigan
- Javascript Basics Part 10 Minnesota
- Javascript Basics Part 10 Mississippi
- Javascript Basics Part 10 Missouri
- Javascript Basics Part 10 Montana
- Javascript Basics Part 10 Nebraska
- Javascript Basics Part 10 Nevada
- Javascript Basics Part 10 New Hampshire
- Javascript Basics Part 10 New Jersey
- Javascript Basics Part 10 New Mexico
- Javascript Basics Part 10 New York
- Javascript Basics Part 10 North Carolina
- Javascript Basics Part 10 North Dakota
- Javascript Basics Part 10 Ohio
- Javascript Basics Part 10 Oklahoma
- Javascript Basics Part 10 Oregon
- Javascript Basics Part 10 Pennsylvania
- Javascript Basics Part 10 Rhode Island
- Javascript Basics Part 10 South Carolina
- Javascript Basics Part 10 South Dakota
- Javascript Basics Part 10 Tennessee
- Javascript Basics Part 10 Texas
- Javascript Basics Part 10 Utah
- Javascript Basics Part 10 Vermont
- Javascript Basics Part 10 Virginia
- Javascript Basics Part 10 Washington
- Javascript Basics Part 10 West Virginia
- Javascript Basics Part 10 Wisconsin
- Javascript Basics Part 10 Wyoming
Related Articles
- Javascript Basics Part 5
Up until now we have been focusing on the language constructs of JavaScript: if statements, loops, functions, etc. In this primer we are going to take a step back and cover the inner workings of some of the native JavaScript objects: Strings, Numbers and Arrays.
- JavaScript Basics Part 2
- Javascript Basics Part 6
- Javascript Basics Part 11
- Javascript Basics Part 7
- JavaScript Basics Part 1
- Javascript Basics Part 12
- Javascript Basics Part 9
- Javascript Basics Part 3
- Javascript Basics Part 4
Rate Article
     
Articles Insider

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Advertising Engineering Home Services Retail & Consumer Services
Business Services Entertainment Industrial Goods & Services Software
Career Family Insurance Technology
Cars Financial Services Internet Telecommunications
Computer Hardware Food & Beverage Legal Transportation & Logistics
Construction Health Pets Travel
Education Home Electronics Real Estate Wedding