Fixes for XHR-Polling

I implemented the gist provided by @rsattar.
It fixes issue #65 and #83.