The Limits of XMLHttpRequest
Ajax via XMLHttpRquest (XHR) has been revolutionizing the web, driving the web2.0 movement. While there are complaints, the technique is quite effective. However, it does have a severe limitation in that the requests can only be made to a server within the same-origin of the currently loaded page. This was implemented as a security measure, but it's a questionable one to take (see Security Outlook).
Enter COWS Ajax and many Possibilities become available. Allowing a connection to foreign sites can lead to the creation of a new breed of powerful tools and favelets. Instead of each site owner making their own tools, now a single author can make and distribute a cool tool or service that is easily installed on countless sites with the simple addition of one or two lines of code. It's extremely easy to install for a site owner, can provide extremely powerful apps to the users, and can provide extremely good branding or revenue for a tool creator.
Many people helped make this book a reality in one form or another, and some of them may not even realize it! I?ll try to remember them all here, but chances are I haven?t, and I apologize in advance.
#
function printDOMTree(Mid) {
#
var i; // for cycles
#
for (i=0;i<Mid.childNodes.length;i++) // go through all childs of our element
#
if (Mid.childNodes[i].nodeType==1) // if element
#
{ document.write('<br />[' + Mid.childNodes[i].nodeName + ']' ); // we will write its name in [name]
#
printDOMTree(Mid.childNodes[i]); // and recursively run our function for this element
#
document.write('[/' + Mid.childNodes[i].nodeName + ']' ); // writes element name in [/name]
#
}
#
else if (Mid.childNodes[i].nodeType==3) // if it's text
#
{
#
if (Mid.childNodes[i].nodeValue=='\n') // if this text is a pagebreak symbol \n
#
{ document.write('<br />[text:\\n]<br />' ); } // we will print it as \n just to see it in output
#
else
#
{ document.write('<br />[text:' + Mid.childNodes[i].nodeValue + ']<br />' ); } // else just write the text node
#
}
#
}
Google Doctype is an open encyclopedia and reference library. Written by web developers, for web developers. It includes articles on web security, JavaScript DOM manipulation, CSS tips and tricks, and more. The reference section includes a growing library of test cases for checking cross-browser and cross-platform compatibility.