I recently enabled the taxonomy module in Drupal so that I could easily categorize things when creating new content. Everything seemed to be working fine, but when I created a post yesterday I got the following error when I started entering keywords to tag my article:
An HTTP error 0 occurred.
http://itnitwit.com/taxonomy/autocomplete/2
As most error messages are this wasn't very useful to me except for the reference to autocomplete. I did a quick search on the Internet and there were just a handful of hits, and one particular one did get my attention http://drupal.org/node/211525. So I opened up my trusted Firefox browser again and turned on Firebug (folks this is a must add-on regardless if you do any web programming - it can help track down issues quickly and is a great learning tool). I then went to my content page and tried entering some keywords again. The Net panel in Firebug showed that there was an HTTP request each time via XMLHttpRequest (i.e., AJAX). I opened up autocomplete.js script, which Drupal uses for the autocomplete feature. Sure enough there was a call to JQuery ajax() method. I examined the actual request a bit more closely and noticed that the request was being sent to itnitwit.com domain. Bingo!! My problem was that the document containing the script was loaded from www.itnitwit.com (notice the www. prefix). This is where the same-origin policy kicks in. The ajax() method makes use of the XMLHttpRequest object, that in turn allows scripts to make HTTP requests. However, this is only allowed to the web server which the document referencing the script was loaded from. The protocol, host, and port must match exactly; otherwise, the request will fail and the status property of the XMLHttpRequest object will be 0 (hence where the HTTP 0 came from in my particular situation). In my case itnitwit.com and www.itnitwit.com hostnames did not match exactly.
I was a bit confused at first because one can access my site with either URL. This magic is accomplished with a rewrite rule in my .htaccess on my site. Basically there is a condition that checks for itnitwit.com and rewrites the host to www.itnitwit.com and sends 301 response. So requests are always coming from the www.itnitwit.com domain. You'll notice from the error message at the beginning of this post that the domain did not have the www prefix. I therefore researched a bit more and found that the $base_url in my site's settings.php file was set to 'itnitwit.com'. Drupal - or more specifically - the autocomplete script uses the $base_url to build the URL used by the AJAX request to the server. Although my web server rewrites the host, same-origin policy prevented my browser's script engine from even sending the request out.
So word to the wise: remember to check your configurations to make sure your base URL matches the domain origin your site content comes from.