Fixed synchronous ajax by blocking on the correct thread

this needs to be tested still. A race condition may potentially still
exist.