Optimised AJAX Call

Link

A nice way to manage AJAX calls written by Dustin Diaz.

	var asyncRequest = function() {
	  function handleReadyState(o, callback) {
	    if (o && o.readyState == 4 && o.status == 200) {
	      if (callback) {
	        callback(o);
	      }
	    }
	  }
	  var getXHR = function() {
	    var http;
	    try {
	      http = new XMLHttpRequest;
	        getXHR = function() {
	          return new XMLHttpRequest;
	        };
	    }
	    catch(e) {
	      var msxml = [
	        ‘MSXML2.XMLHTTP.3.0′,
	        ‘MSXML2.XMLHTTP’,
	        ‘Microsoft.XMLHTTP’
	      ];
	      for (var i=0, len = msxml.length; i < len; ++i) {
	        try {
	          http = new ActiveXObject(msxml[i]);
	          getXHR = function() {
	            return new ActiveXObject(msxml[i]);
	          };
	          break;
	        }
	        catch(e) {}
	      }
	    }
	    return http;
	  };
	  return function(method, uri, callback, postData) {
	    var http = getXHR();
	    http.open(method, uri, true);
	    handleReadyState(http, callback);
	    http.send(postData || null);
	    return http;
	  };
	}();

Originally found here

Disable the Firebug extension

Link

Useful for pages containing a lot of javascript that might bring Firefox to a grinding halt if it’s not disabled.

	if (! ('console' in window) || !('firebug' in console)) {
	    var names = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', 'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd'];
	    window.console = {};
	    for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};
	}

Originally found here