jQuery

411 Length Required

Was getting a 411 error response with the message Length Required when making an ajax call from jQuery... the unexpected solution is to pass in an empty data object, like so:

$.ajax({
  url: url,
  type: 'POST',
  data: {},    //  <- set empty data
  success: function(data, textStatus) {
    // do something
  }
});

Source: http://groups.google.com/group/jquery-en/browse_thread/thread/22828981cf...

Resolved: Logging to Firebug console breaks IE

The firebug console is great for debugging javascript -- but it's really annoying when you want to quickly check something in IE and can't without first removing all your debug statements to avoid a bunch of javascript errors.

Here's a handy log function which checks first that firebug is in use before trying to log to the console. The function is a no-op in IE.

log_debug = function() {
  if(window.console && window.console.firebug) console.log.apply(this, arguments)
}

log_debug('foo', 'bar', 'bash')

Using a context

$('.foobar', context)

...is the same as:

context.find('.foobar')

...but you can also pass in a DOM element:

$('.foobar', this)

...which would be the same as:

$(this).find('.foobar')

Syndicate content