Computer Programmer

AJAX: Status of “0” for an XMLHttpRequest

If you experience getting a status of “0” returned during an XMLHttpRequest, then the problem could be the result of several things. However, a status of “0” for an XMLHttpRequest (XHR) in AJAX quite often indicates a network error or a CORS (Cross-Origin Resource Sharing) issue. You might especially see this problem if you’re developing on a local machine, and trying to access a remote resource of some sort, and you probably need to set the Access-Control-Allow-Origin header. Here’s how.

Continue reading »

How to Shorten document.getElementById in JavaScript

After you’ve been writing JavaScript for a while you’ll eventually become aware that it’s a real pain in the neck to keep on typing “document.getElementById”. It takes time to type and, even if you’re using some auto-complete editor feature, it still takes up visual space in your editor and also byte-space in your file. So, is there a better way? Sure there is; it’s the same idea that you’ve probably seen in jQuery or similar libraries, with those mysterious $ signs everywhere. 

Continue reading »