gregdoolittle.com

chronicling the fate of a warrior: Ajax the Great

January 19th, 2007

I bought my text book for my Ajax class (I also bought my book for my Database class, but hey, that’s just not exciting!). I hope to document my experience learning Ajax in this blog. The class doesn’t begin until March 21st, but I’m planning to work through as much of the material as I can before then, so I can apply it to my new job.

Just finished the Chapter 1 tutorial. Some points to remember:

•The main goal of using Ajax: to reduce the need for data transfer within a web page, therefore increasing your site’s ability to react quickly to user activity.
•Ajax should be able to function in every JavaScript-enabled browser.
•The Ajax request object has not been standardized among browsers. In Firefox/Safari/Opera/IE7, you use the XMLHttpRequest object. In IE6 you use ActiveXObject(”Msxm12.XMLHTTP”). And in IE5 and earlier you use ActiveXObject(”Microsoft.XMLHTTP”). You should account for this every time you create an Ajax request object.
•An Ajax-script is usually called by an event handler (onClick, onChange, onMouseOver, onBlur, onKeyUp, etc.).
•The browser keeps track of a request’s “ready state”. When the ready state is equal to “4″, it means the request is done retrieving information. The DOM aspect of the script must wait until this ready state is achieved. Otherwise, the script will finish running before the information is available.

Every Ajax script will require an object to hold the request, followed a bit of browser-sniffing to apply the appropriate type of Ajax object:

var request = null;
 try {
  request = new XMLHttpRequest();
 } catch (trymicrosoft) {
  try {
   request = new ActiveXObject("Msxml12.XMLHTTP");
   } catch (othermicrosoft) {
    try {
     request = new ActiveXObject("Microsoft.XMLHTTP");
     } catch (failed) {
      request = null;
     }
   }
 }
 if (request == null)
  alert("Error creating request object!");

Usually followed by these lines of code:

var url = "example.php";
request.open("GET", url, true); // true means this is an asynchronous request
request.onreadystatechange = updatePage; /* updatePage() is a function that will use DOM
methods to alter the page hierarchy */
request.send(null); // the request.

If you’d like to see my first, and very dorky, Ajax “application”, you can get to it here (update 01/21/07: just added a random parameter to the URL of the request object, which fixes a bug in IE and Opera). In this case the amount of data transfer saved by using Ajax (as opposed to requesting an entire HTML file) is so minimal that it hardly justifies the time spent constructing the Ajax script. But imagine that this feature was part of a page that did have a lot of elements (say, a couple of 8MB image objects). In that case, using Ajax for such a minute section of a page would be worthwhile, because it would avoid reloading the large amounts of data sitting around elsewhere on the page.

curse of the black perl

October 21st, 2006

Last week I finished my class in JavaScript. My final programming assignment wasn’t too exciting. Basically had to create a user registration login system. So… in a nutshell, the class covered all the basics of JavaScript: a healthy dosage of html review, writing good code in JavaScript, variable scope, functions with parameters, math functions, decimal formatting, the date object, arrays, loops, conditionals, recursive functions, dhtml and DOM scripting, event handlers, IE special effects, status bars, pattern matching and regular expressions, and cookies.
There were a few chapters in our book that we missed, and I really want to go back and learn the stuff before I look for jobs: the drag-and-drop feature, dynamic content, and the node tree.

Tonight I had my first day of Perl. The teacher seems a little rusty (I’m being very polite by only calling him “rusty”), and hopefully he’ll get get his groove back soon. I had to remind him that JavaScript does not run on the server, but Java does. Yikes! That was a bad sign. I’m sure he’ll get back into the swing of things soon enough. For the time being, I’m just keeping my fingers crossed, hoping I won’t drown. I read the intro to my book “Learning Perl” by Randal Schwartz & Tom Christiansen, and the Perl intro documentation through my terminal. We’re covering roughly two chapters a week, so it’s gonna go quick. So for the next ten weeks, if I haven’t updated, you’ll know why.

boagworld.com

August 24th, 2006

i just found my new mentor for web design: boagworld.com. it’s a pretty cool site for beginners. they cover a lot of stuff you would never talk about in a class. and they stay very current with web standards. neato.

fall semester CSM

August 18th, 2006

i’m taking intro to javascript as well as php (with mysql) this fall. both classes are online, which is pretty convenient. javascript should come fairly quickly since i took intro to programming with java. but php is kinda scary. i’m a little worried that this particular class will be too much all at once. it seems like a really cool language, based on how much you can do with it, and how simple everything looks on paper, but it’s also intimidating. i don’t have the required pre-requisites, but the teacher said i could take it if i’m willing to work really hard. i’ve never used mysql, so that’s another intimidating factor.

i’ve been lagging on syndicating this journal to my website. i need to officially put a hold on that idea. i’ve been meaning to spend time on it, but with weddings and birthdays and everything else, i’ve just been too busy. at some point during this semester, i’ll take another look at “php-embedding” this site. i don’t have time now (especially with school starting), and it’ll be easier then.

i set up a little mail() script on my website. i’m a little afraid of it being abused so i don’t want to post a link to it. this was my first (server) script; it was really exciting to see the script work when i sent myself an email from my domain. now i’ve got to figure out how to validate input fields… that should be a challenge!

xml + javascript = ???????

August 4th, 2006

i took my final test for XML last night. i think i did okay. only needed to score a 78 to get an A in the class. so i’m not worried about it at all.

i start javascript on the 16th. it’s a short course, ending in mid-october. as soon as i take javascript, i’ll be academically “prepared” to look for jobs. but i will still have to assemble a portfolio. the one i have on my website is empty, and i still haven’t taken photos of my artwork or organized all the stuff i have at work. i might also take a course in relational databases (mysql and oracle), although i should probably spend more time on polishing my freelance projects and acquiring more of them instead.

must.. syndicate…. journal…

syndicating my journal

August 1st, 2006

i want to take the rss feed of this journal, and put it on my website. i started to write the xslt that would format my rss feed into something that looked like it came from my website. i got through a good part of it before realizing that i wouldn’t be able to reference the xslt from my rss. why not? :: as far as my class was concerned, the only way to perform an xslt transformation on an xml document was to have a line referring to the xslt in the xml doc. i have no way of modifying the rss document to add any style sheet or transformation template to it… :: so, i’ve been researching different approaches to the solution. the two that sound like they might work best are javascript and php.

javascript solution would mean learning about DOM and writing a script that will load my rss file as an xml document, load my xslt document, and return the result of the transformation. this script would be inserted on the body of a page dedicated to syndicating my journal. it would automatically update itself each time the page is loaded. the only problems with this method of syndication are that the content will not be searchable by a web-spider/search-engine (no biggie for me), and that not all browsers are javascript enabled. php is a very similar solution, except that the two javascript problems are solved, and a new one arises: i have no clue how to write php. i’m going for the javascript / DOM model for accessibility reasons. it will also be a nice primer for my javascript course i’m taking next semester.

Powered by WordPress