innerHTML and Ajax – Bad Combination

Written on January 7, 2008 – 4:54 pm | by Hii Hiong Ching |

Ajax is comparatively new to the world of programming and software. So far, only few people have cracked the use of this program without the use of toolkits. Only God knows how many people who can actually code without using toolkits but I’m willing to bet that they don’t really reach that much. Saying that only a rocket scientist could figure out how to properly code Ajax is probably an understatement considering its requirements from a developer.

But if you have figured Ajax out, good for you. On my end, I was able to do a little bit of Ajax project from time to time but I still have troubles figuring things out. It’s still a matter of trial and error for me.

In my journey in figuring out Ajax, I came into contact with one of the peculiar situation that will only happen to Ajax. If you have been to the world of programming language, you may already have encountered innerHTML. This little tool is often used by programmers to easy write objects in a DIV. Although the longer way of using DOM is also good, programmers naturally select the easier way… including me.

But things got awry when I tried to use innerHTML while I was building an Ajax based software. You may already have heard how Ajax can be as complicated as it combines different programming languages into one complicated program. The end result will always be a beauty but it will take your time and effort just to make one simple program. By all means, I have to look for way to make my Ajax coding a little bit easier. Instead of using DOM for myDiv, I decided to use innerHTML. Although Ajax still took time to be finished, using innerHTML helped me get through the challenges in creating this complicated program.

Thinking that I already have a pretty good Ajax software I decided to make it run. But as soon as it started, I figured out something is definitely wrong with my program. The information I entered doesn’t seemed to be processing as planned. Worst memory leaks seemed to be plaguing the program, causing me to re-evaluate the entire program right from the scratch. Soon enough, I traced the problem in innerHTML. Apparently innerHTML cannot process the XML documents that well causing it to bypass, or even withheld some information. Although memory leaks doesn’t happen in Mozilla, more than 80% of the worldwide users are into IE and this is where the problem usually starts. The only resort for this Ajax based program to work is to change the innerHTML into DOM. I know it’s going to be really complicated but considering the consequences, you should stick to the longer but safer road of DOM. Ajax is not only for rocket scientists but also patient rocket scientists.

So if you want a stronger Ajax-based software that could practically be stable in IE; ignore innerHTML as much as you can and use DOM. Although it will take some time, you may never have to review your program again.

Popularity: 8% [?]

Post a Comment

About Office-it.orG

This is a site to share my knowledge, discovery and experience related to my hobby and work. Most articles on this site are related to web design, web development, graphic design, short reviews, tips and tricks. I sometimes write some about Microsoft Office Application too.

Want to subscribe?

RSS Subscribe in a reader Or, subscribe via email:
Enter your email address:  
Find entries :