Moodle Unexpected Output while processing AJAX request

I had this one come up when expanding the Site Administration menu:

Coding error detected, it must be fixed by a programmer:  
Unexpected output whilst processing AJAX request.  

This could be caused by trailing whitespace. Output received: ' '

What causes it is there is a new function in later versions of Moodle in lib/ajax/ajaxlib.php called “ajax_check_captured_output”. This is a useful check for developers, and therefore when the site is in DEVELOPER debug mode it throws an exception. You can change the debug mode to something less than DEVELOPER and you shouldn’t get an exception (but note that there is still an underlying problem).

One catch is that if the site administration navigation is failing, you can’t actually get to Site administration > Development > Debugging. Easy work around, visit and adjust your debugging settings there.