how to return data from php to jquery AJAX -
i'm new ajax, want learn. have set form (formidable pro) submitted via ajax. in submit button have on onclick function:
<div class="frm_submit"> <input id="btn-max-hyp" onclick="add_customer()" type="submit" value="[button_label]" [button_action] /> <img class="frm_ajax_loading" src="[frmurl]/images/ajax_loader.gif" alt="sending"/> </div>
my custom js file:
jquery(document).ready(function($){ $('#form_maxhyp').on("submit", add_customer); function add_customer () { var form_maxhyp = $(this).serialize(); $.ajax({ type:"post", url: frontendajax.ajaxurl, data: form_maxhyp, success: function(data) { $("#test").html(data); } }); return false; } });
and last code in function.php
<?php add_action( 'wp_enqueue_scripts', 'add_frontend_ajax_javascript_file' ); function add_frontend_ajax_javascript_file() { wp_enqueue_script( 'ajax_custom_script', get_stylesheet_directory_uri() . '/ajax-javascript.js', array('jquery') ); wp_localize_script( 'ajax_custom_script', 'frontendajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ))); } add_action('wp_ajax_add_customer', 'add_customer'); add_action('wp_ajax_nopriv_add_customer', 'add_customer'); function add_customer($entry_id, $form_id) { if ( $form_id == 6 ) { global $wpdb, $frmdb; $form1 = '6'; $value = $_post['item_meta'][222]; /* lot of if , else statements */ /* echo values */ echo "'".$value. "'"; } die(); }
i want set value div. in console log error: referenceerror: add_customer not defined.
probably it's simple i'm not seeing. i'm doing wrong here?
in custom js file have :
jquery(document).ready(function($){ $('#form_maxhyp').on("submit", add_customer);
in case add_customer
read variable.
change this: jquery(document).ready(function($){ $('#form_maxhyp').on("submit", add_customer());
to make call function!
Comments
Post a Comment