This can work with AJAX, but the error is with Gravity Forms and when it enqueues JavaScript files. I can’t say that this will work for you, but this solution may help: https://hereswhatidid.com/2013/01/move-gravity-forms-jquery-calls-to-footer/