• RSS Unknown Feed

    • An error has occurred; the feed is probably down. Try again later.
  • Meta

Ajax Polling

Ajax polling is when a browser makes an asynchronous request to a server at regular intervals to see if anything has changed on the server. When it is determined that a change has been made, the page can be updated accordingly.

For example, a page showing product information which includes quantity available, could be polling the server consistently to see if the quantity available has changed. If so, that can be immediately reflected on the page, without any interaction from the user. This simple technique has a multitude of uses – it’s simply up to designers and developers to use their imaginations and find the most appropriate places to use this tool.

Jesse James Garrett: The inventor of the term Ajax

The first person to ever use the word Ajax to refer to the package of technologies that comprise the transferring of XML and other data to and from web servers via HTTP was Jesse James Garrett. Garrett first used the term in February 2005 in an article he wrote for his company, Adaptive Path, titled ‘Ajax: A New Approach to Web Applications.’

In this article, he references CSS, XHTML, DOM, XSLT, XML, XmlHttpRequest and JavaScript as the technologies that define Ajax. Needless to say, this is an incomparable piece in the history of the Internet. That, coupled with the fact that his name is ‘Jesse James’, makes Mr. Garrett the man.

JavaScript XHR: Acronym for XmlHttpRequest

The acronym XHR stands for XmlHttpRequest, which is an API used by JavaScript to transfer XML and other data via HTTP to and from a web server. The XmlHttpRequest API is core to Ajax applications and primarily utilized to build dynamic, responsive Internet applications.

Related articles:
Creating an XmlHttpRequest object for Ajax
XmlHttpRequest open Method
XmlHttpRequest send Method
XmlHttpRequest onreadystatechange
XmlHttpRequest readyState values
XmlHttpRequest status Property values
Getting Data from a Server for Ajax
Simple Ajax Example Tutorial with ColdFusion
XmlHttpRequest responseXML Property
XmlHttpRequest responseText Property
XmlHttpRequest: Difference Between Firefox and Internet Explorer

XmlHttpRequest Difference Between Firefox and Internet Explorer

The XMLHttpRequest object is initialized differently in earlier versions of Internet Explorer as compared to Firefox.

As of Internet Explorer 7, an XMLHttpRequest be can be initialized simply with:

new XMLHttpRequest();

The preceding always worked with Firefox. In earlier versions of Internet Explorer, however, the libraries differed on how to initialize XMLHttpRequest. For this reason, both of the following calls have to be attempted as well:

new ActiveXObject('Msxml2.XMLHTTP');
new ActiveXObject('Microsoft.XMLHTTP');

This should be done as a try/catch block, with the call that will work in Firefox and Internet Explorer 7 coming first as it is the most likely to succeed.

try {
  var objXHR = new XMLHttpRequest();
} catch (e) {
try {
  var objXHR = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try {
  var objXHR = new ActiveXObject('Microsoft.XMLHTTP');
} catch (e) {
  document.write('XMLHttpRequest not supported'); }
}
}

Related Articles:
Creating an XMLHttpRequest Object for Ajax
JavaScript Try Catch Finally

JavaScript Constructors

A constructor is used to define a class of objects. To create a constructor in JavaScript, use the new keyword, followed by a function call. The function that is called is where the constructor is defined. In this function, set any properties that should always be present for the constructor.

Consider the following example:

function Square(intSideLength)
{
this.perimeter = 4*intSideLength;
this.area = 2*intSideLength;
}

In the preceding example, the function is the constructor. Use the this keyword to assign properties directly to the constructor. The constructor is now ready to be used:

var mySquare = new Square(4);
document.write(mySquare.perimeter);
document.write(mySquare.area);

Object Oriented JavaScript

I am often asked the question, “Is it possible to use object oriented principles with JavaScript.” The answer to that is “not completely, but you can simulate objects in JavaScript.” I am planning to write a series of articles on how to accomplish this through the use of constructor functions and prototype objects. As I do, I will add links to those articles here. Stay tuned…

JavaScript is an Object-Oriented Language
JavaScript Constructors
JavaScript Prototypes
JavaScript Instance Properties
JavaScript Instance Methods