We go in mid-October and we buy our tickets ahead of time. We know we are definitely going and I would rather not have to buy them in the park in case there are lines. But many do buy them onsite with no problems.
You can buy them at WDW, but if you're going very close to Halloween or on Halloween itself, you might risk having it sell out.