Change $.post to $.ajax for synchronous