The recent tax bill did allow 529 money to be used for private K-12 schools...not sure exactly what the requirements would be and whether an online school would meet them or not.
You can contribute money and take it out right afterwards, but there isn't much benefit to doing so. You can think of a 529 kind of like a Roth IRA in that you contribute post-tax dollars and the growth is tax-free. If the time from contribution to withdrawal isn't very long, the growth won't be very much, so the benefit from doing this maneuver is pretty limited.
The one exception would be if you live in a state that gives a state tax deduction on your 529 contributions. In this case contributing to the 529 and taking the money right back out again to pay for that year's tuition can pay off a little bit.