Skip to main content
2 of 2
deleted 82 characters in body
david.binda
  • 3.4k
  • 1
  • 20
  • 16

ajaxurl is set only in admin. If this is a frontend ajax (looks like it due to nopriv), you have to localize the script on enqueueing:

add_action( 'wp_enqueue_scripts', 'my_enqueue' );
function my_enqueue($hook) {
        
    wp_enqueue_script( 'ajax-script', plugins_url( '/js/my_query.js', __FILE__ ), array('jquery'));

    // in javascript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value
    wp_localize_script( 'ajax-script', 'ajax_object',
            array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'we_value' => 1234 ) );
}

In the JS file, you can reach the ajax_url as a variable of ajax_object:

jQuery.ajax(
        ajax_object.ajax_url, {
        action: 'lu_ajax',
        status: 'enabled'
        },
        success: function (a) {
        alert(a)
        }

See http://codex.wordpress.org/AJAX_in_Plugins

david.binda
  • 3.4k
  • 1
  • 20
  • 16