Forum Replies Created

Viewing 2 replies - 61 through 62 (of 62 total)
  • Thread Starter fhwebdesign

    (@fhwebdesign)

    Move your add action call to ‘wp_ajax_fhw_do_ajax_request’ to outside the enqueue scripts callback. admin-ajax.php requests do not try to enqueue scripts. Your add action call can execute on plugin load, it does not need to be in a callback.

    As I understand, I should use this code like so

    add_action( 'wp_enqueue_scripts', 'fhw_register_script' );
    add_action( 'wp_ajax_fhw_do_ajax_request', 'fhw_do_ajax_request' );
    function fhw_register_script() {
    	wp_register_script( 'fhw_formular', plugins_url( '/js/formular.js', __FILE__ ), array( 'jquery' ) );
    	
    	wp_enqueue_script( 'fhw_formular' );
    	
    	wp_localize_script( 'fhw_formular', 'ajax_object',
                array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'we_value' => 1234 ) );
    	wp_enqueue_script( 'fhw_formular' );
    }

    The 400 Bad Request error persists.

    Thread Starter fhwebdesign

    (@fhwebdesign)

    Alright, this is my code how I am calling it

    jQuery(document).ready( function($) {
    	
    	$('input').bind("change", function(e) {
    		onSelect();
    	});
    	
    	
    });
    
    function onSelect() {
    	var data = {
    		'action': 'fhw_getTyp',
    		'typ' : this.value
    	};
    	jQuery.post(ajax_object.ajax_url, data, function(response) {
    		$(".ergebnis").html(response);
    	});
    };
    • This reply was modified 6 years, 9 months ago by fhwebdesign.
Viewing 2 replies - 61 through 62 (of 62 total)