# Loading Gravity Forms with AJAX by Shortcode

**URL:** <https://community.gravityforms.com/t/loading-gravity-forms-with-ajax-by-shortcode/12815>\
**Category:** Get Help\
**Tags:** custom, gform\_force\_hooks\_js\_output\
**Created:** [June 13, 2022, 7:13am UTC](https://community.gravityforms.com/t/loading-gravity-forms-with-ajax-by-shortcode/12815 "2022-06-13T07:13:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![user5b211e703e5b09.0](https://avatars.discourse-cdn.com/v4/letter/u/b9e5f3/32.png) [@user5b211e703e5b09.0](https://community.gravityforms.com/u/user5b211e703e5b09.0)\
**Post date:** [June 13, 2022, 7:13am UTC](https://community.gravityforms.com/t/loading-gravity-forms-with-ajax-by-shortcode/12815/1 "2022-06-13T07:13:54Z")

</div>

Hi,

I am having issues with the form submission on my Gravity forms which I have loaded via AJAX.

On my loaded page, I have a button which triggers an AJAX event to fetch a template part which contains a shortcode for Gravity Forms.

On the main page I have this preloaded to ensure styling works and the JS output.

```auto
add_filter( 'gform_force_hooks_js_output', '__return_true' );
gravity_form_enqueue_scripts( 2, true ); // Form_Id = 2

```

In my Javascript file I have:

```auto
$.ajax({
	url: VC.ajax_url,
	method: 'POST',
	async: false,
	data: {
		action: 'fetch_form',
	},
	success: function( response ) {
		t.elements.results.html( response );
		t.elements.spinner.fadeOut();
	},
});

```

Now I have tested the form submission with AJAX=“true” and AJAX=“false”.

When I use AJAX=“false”, The URL the form is posted to below, except I only get a response of 0 displayed.

```auto
/wp-admin/admin-ajax.php

```

If I use AJAX=“true”, The URL the form is posted to is:

```auto
/we-buy-motorhomes/wp-admin/admin-ajax.php#gf_2

```

This then errors in console as it’s not a valid URL.

Can anyone point me in the right direction? I have checked StackOverflow and some posts on here which all have similar errors, but seem to be older versions?

I am up to date and currently using Gravity Forms Version 2.6.3.

Thanks

---

<div class="post-metadata">

**Author:** ![user5b211e703e5b09.0](https://avatars.discourse-cdn.com/v4/letter/u/b9e5f3/32.png) [@user5b211e703e5b09.0](https://community.gravityforms.com/u/user5b211e703e5b09.0)\
**Post date:** [June 14, 2022, 1:16pm UTC](https://community.gravityforms.com/t/loading-gravity-forms-with-ajax-by-shortcode/12815/2 "2022-06-14T13:16:43Z")

</div>

Anyone able to point me in the right direction? GF support unable to support.

---

<div class="post-metadata">

**Author:** ![user5b211e703e5b09.0](https://avatars.discourse-cdn.com/v4/letter/u/b9e5f3/32.png) [@user5b211e703e5b09.0](https://community.gravityforms.com/u/user5b211e703e5b09.0)\
**Post date:** [June 16, 2022, 11:29am UTC](https://community.gravityforms.com/t/loading-gravity-forms-with-ajax-by-shortcode/12815/3 "2022-06-16T11:29:51Z")

</div>

This is now resolved.

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [June 16, 2022, 7:56pm UTC](https://community.gravityforms.com/t/loading-gravity-forms-with-ajax-by-shortcode/12815/4 "2022-06-16T19:56:35Z")

</div>


