jQuery and AJAX

I have been playing around with jQuery a lot, as I am building a new site devoted to ski mountaineering. The site is progressing slowly, as I don’t have a lot of spare time these days. Hence my desire to use a js library to speed up development and abstract the browser differences.

I really enjoy jQuery so far, and am amazed at how quickly I can build out functionality. The maintainability of the code I am writing is a different story. Anonymous functions nested n times; not sure that sites right with me if I was trying to write robust and testable code. But for a personal site, it works and the impetus is on me to write good code (although some libraries/frameworks make it easier).

One thing that tripped me up was ajax error handling. I didn’t want to use the convenience methods like $.get because I think you need to plan for an error. I am using an alert if the ajax call fails, so a user would know why clicking on a link was
not doing anything. In IE, it was triggering two alerts. I was putting in a bogus url, as I am developing locally and that is the easiest way to trigger an error. I am still not sure why it called my error function twice in IE and once in FF, but in reading the documentation I found out three parameters can be passed into the error function. The second and third parameters, error string and the exception, are null in the extraneous error call, so I can filter out the extra call. Not sure if it is because I am testing locally and the file doesn’t exist, rather than a web server returning a 404 error. I’ll have to run a test on a real server to see. Anyone else have this problem?

Leave a Reply