Showing posts with label AJAX. Show all posts
Showing posts with label AJAX. Show all posts

November 11, 2010

Web Development with JavaScript and AJAX

It seems like JavaScript and AJAX are becoming more and more necessary to create professional, interactive web sites. Basic HTML and even CSS just won't cut it. People expect the "bling" that JavaScript provides. I have mixed emotions about JavaScript though. It can really make a website stand out, but compared to traditional languages and development environments, it can be a pain to develop, debug, and maintain.

Part of me would say that Silverlight or Adobe Flex provides a easier environment to develop in, but they can be very heavyweight for most web sites. Maybe I just haven't found the right JavaScript framework or toolkit that really works well and makes sense. It seems like jQuery and the Google Web Toolkit are two of the most common and well known systems. jQuery seems a little more flexible, and the Google approach seems to be very tightly coupled with Java. Since I do most of my development with C# and ASP .NET, jQuery looks like a more promising solution.

October 16, 2009

Weird Javascript and AJAX errors

I recently implemented some JavaScript logging on one of the web sites that I work on. Something like this: Using XMLHttpRequest to log JavaScript errors. It is working well and helping me uncover errors in my code, but many of the remaining errors that I see make little or no sense. Here is a list of some of the oddities that I have seen, that have been unable to reproduce in my development environment since that are so rare and sporadic:

  1. There are times that certain JavaScript functions and variables cannot be found. Many of these are defined in external JavaScript files. In the case of Firefox I see errors when an external file fails to load for some reason. Internet Explorer give no such indication, but I have to assume that the same thing is happening. The Firefox errors do not give any details as to why the file failed to download.
  2. Sometimes the server side logging gets blank errors. So somehow my logging page gets hit with no data, this shouldn't be happening.
  3. The most frequent AJAX error is when making an AJAX call, the data returned is incomplete. I know that the readyState property is set to 4 and the status is 200, but looking at the actual length of the data (from the Content-length in the header) and comparing it to the length of the data in responseText, some data is missing. Sometimes it is almost the right size but many times it is only a fraction of the expected size. This is even after taking into account the fact that the data is UTF-8 encoded. The data size can be anywhere from 20 to 30KB, so I have wondered if the amount of data may be a contributing factor.
  4. The other AJAX error is non-standard status codes. With FireFox I see responses of 0, and Internet Explorer I see the infamous 12000 error codes like 12019 12029 12030 and others.
So far here is what I have done to reasearch and or resolve these issues:
  1. I haven't found anything definitive to help when files fail to load, but I am going to enable gzip compression for javascript files on IIS 7 to see if it might be to due to slow connections timing out. Hopefully the smaller file size will help these requests succeed more often, but this is not a complete solution. I expect to continue to see this problem.
  2. This one has me stumped. The JavaScript logging code should always be passing an error message, with the error data, even the JavaScript error handling has no content. I have no idea why these would come back blank. Maybe the request is timing out, or I have an issue with the server side logging code not waiting until all of the data is ready.
  3. I haven't had much luck with this one either. So far I have added some retry code, so if I get a failure, I just try again. This appears to work about 75% of the time, but I currently limit it to 1 retry, so I still see some failures. This also seems like a less than ideal solution, but maybe it is the best I can do.
  4. Same as number 3, I just try the request again, and is succeeds about 75% of the time. The requests are over HTTPS and some information I've found indicate that this might be a problem with Internet Explorer trying to reuse connections and failing, but I have not tried adding the Connection: Close header yet.
These all seem very odd to me. Most of them occur on both Firefox and Internet Explorer 6, 7, and 8, but very infrequently in almost all cases, but each case still represents someone that will probably have a poor customer experience on the web site. I have to assume that errors like this are pretty common on other sites, but how many people have JavaScript logging set up that would even notice them.

September 24, 2009

Sporadic ASP .NET AJAX errors

I've got a website that is having very sporadic ASP.NET AJAX errors. I have a JavaScript logging solution that reports back to me when any JavaScript errors occur on my web pages. There are two errors that occur most frequently are ['Type not defined] and ['Sys' not defined]. These both are objects defined by the .NET AJAX extensions. It appears that in some cases (probably 1% or less) these types fail to initialize. The issue occurs on Internet Explorer 6, 7, and 8. The only way I have been able to reproduce this error is forcing the first ASP .NET JavaScript file to not load. Should I just chalk this up to sporadic internet hiccups? Most of the issues related to this that I've seen in my internet searches are errors that occur constantly because of misconfiguration, but my site works almost all of the time and only has issues occasionally.

The other odd error is that I have is AJAX calls back to our server that fail to return all of the data. The HTTP header indicates one size for the data, and the actual text returned is considerably smaller, anywhere from only 10% to half, and even a few that returned 0 bytes. And this is after accounting for the fact that the data is UTF8 encoded. I have always assumed that if the AJAX call returns, and readyState property is 4 and the status is 200 then the data being returned should be correct, accurate, and complete. This error seems to be across all Internet Explorer versions and I've even seen it with Firefox. Has anyone seen any issues similar to either of these, or have any suggestions as to how to debug this?