Check Laura's suggestion for JS errors first (usually the issue)!
Is this on a new page or on an already published one?
It could be that your code can't find the correct page for displaying the current state. Could be looking for the published version while that is not published yet. Make sure when in edit mode you retrieve the latest version that doesn't need to be published per se.