AJAX async fix

fixes the order of read and writes