Ajax in WordPress – path issue

it needs a full URL because even though it may be the right location relatively on the back end, it’s not on the same on the front end, at the URL where your page is ultimately served.

you’re on the right path with wp_localize_script. you want to enqueue your ajax script, then pass the admin ajax url to wp_localize_script:

function my_init_method(){
    wp_enqueue_script( 'my-ajax-request', plugin_dir_url( __FILE__ ) . 'js/my_ajax_script.js', array( 'jquery' ) );
    wp_localize_script( 'my-ajax-request', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
}
add_action('init', 'my_init_method');

now within your ajax script you can refer to MyAjax.ajaxurl for the URL.

Check this post for a great writeup on properly using ajax in plugins and themes, this is what the WP Codex links to as an example.