Sending variable from ajax on form submit

in your html form add <input name=”action” type=”hidden” value=”test_function”/> . here “value” is your “action_name”. Your ajax call is incorect. Data should be url: “your php action script” data: $(‘form#filter).serialize(), About ajax first try to create ajax on your computer without wordpress. When you understand how ajax work try on WordPress. if you want to … Read more

update_post_meta using ajax

You didn’t set a name attribute in your input tag with the id = “amount”. Set the name as “inpAmount” and try again. <input id=”amount” class=”inpAmount” type=”text” maxlength=”15″ /> should be <input id=”amount” class=”inpAmount” type=”text” maxlength=”15″ name=”inpAmount” /> As previously mentioned, the path to admin-ajax.php looks wrong as well. The wp_ajax nomenclature is also incorrect. … Read more

How to handle 400 status in Ajax [duplicate]

This function will load the JS scripts: function test_ajax_load_scripts() { // load our jquery file that sends the $.post request wp_enqueue_script( “ajax-test”, plugin_dir_url( __FILE__ ) . ‘/ajax-test.js’, array( ‘jquery’ ) ); // make the ajaxurl var available to the above script wp_localize_script( ‘ajax-test’, ‘the_ajax_script’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ) ) ); } add_action(‘wp_print_scripts’, ‘test_ajax_load_scripts’);

get_queried_object_id in AJAX

OK, let’s start from trying to understand, what get_queried_object function does. According to its Codex page: Retrieve the currently-queried object. For example: if you’re on a single post, it will return the post object if you’re on a page, it will return the page object if you’re on an archive page, it will return the … Read more