sklar.com

...composed of an indefinite, perhaps infinite number of hexagonal galleries...

© 1994-2017. David Sklar. All rights reserved.

Javascript Toolkits: They're Here to Help

XMLHttpRequest Quirks and PHP has some tips on making HTTP requests from Javascript (and is not really PHP-focused, despite the title). The brief discussion of the benefits and drawbacks of using XML, HTML, or JSON for data exchange is worthwhile, and I suppose there’s nothing wrong with any of the info about the XMLHTTPRequest object, but I think if you’re doing any moderately serious Javascript stuff that requires HTTP requests (see what wonderful contortions I undergo to avoid saying “Ajax”! Oops.), you’ve got problems if you’re interacting with XMLHTTPRequest (or the IE-equivalents via “new ActiveXObject()”) directly.



Instead, use a library such as Dojo or Prototype. There are a lot of subtleties to making requests work properly – things such as cross-browser support and using different request transports based on the kind of data that needs to be sent to the server. If you start down the road of trying to do all that yourself, you’ll go nuts (or at a minimum, waste your time reinventing). If you ignore all of those subtleties, your app won’t work correctly.



So take advantage of the hard work someone else has already done to solve these problems. We may argue over whether real programmers use emacs or vi or Microsoft Visual InterDev 2006 for .NET Enterprise Architect Edition, but there’s not much support for the “I wave a tiny magnet back and forth just-so next to the hard drive” method of editing these days. Avoid waving the tiny magnet to make HTTP requests from Javascript.

Tagged with php , javascript