Comet, Comet on the Wall: Fix comets sent down via AJAX from within a comet

This fixes a few issues:
 - We centralize comet command generation into `S.jsToAppend`.
 - We fix when we look up `S.jsToAppend` during AJAX processing in comet contexts so we don't miss anything that might be added during the actual AJAX function execution.
 - We make sure not to trigger a second comet request when setting up new comets client-side from within a comet response.

Fixes issue #1645 .
My only concern here is this, which was originally added to deal with some race conditions with wiring, I believe. I don't think what we're doing now will be significantly different, since the fact that it's a `partialUpdate` in both cases means it will be processed as a subsequent message to the comet in both cases, but it's worth pointing out in case anyone disagrees.