Ajax not working when form loaded dinamically using Ajax
-
Hi.
I am loading contact form into floating box when user clicks on button. It is loaded from page (containing form short-code) using ajax. The problem is that Ajax is not working. All the scripts are loaded before the form is loaded but still nothing. When I click submit button, I am redirected to “https://www.myweb.com/wp-admin/admin-ajax.php#wpcf7-f232-o1”. Where is the problem?Here is my code from functions.php:
add_action( 'wp_ajax_my_action', 'my_action_callback' ); add_action( 'wp_ajax_nopriv_my_action', 'my_action_callback' ); function my_action_callback() { $page = get_page_by_path( 'website-audit' ); if($page) { $content=apply_filters('the_content', $page->post_content); } $return='<div id="audit-floating-box"><div class="form">'.$content.'</div></div>'; echo $return; wp_die(); }
And here is code from my script.js file:
$('#button-link').click(function(){ jQuery(document).ready(function($) { var data = { 'action': 'my_action', 'whatever': my_ajax_object.we_value }; jQuery.post(my_ajax_object.ajax_url, data, function(response) { $('#free-audit').append('Got this from the server: ' + response); $('#audit-floating-box').animate({'opacity':1},250); }); }); return false; })
Any ideas what is wrong?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Ajax not working when form loaded dinamically using Ajax’ is closed to new replies.