0

wordpressで動作するようにajax関数を取得し、常にデフォルトの結果を取得しようとしました。私は functions.php に持っています(他の関数の横に)

add_action('wp_ajax_count_results_cal', 'count_results');
add_action('wp_ajax_nopriv_count_results_cal', 'count_results');

function count_results(){
      echo 'test';
      die();
}

function my_theme_scripts() {
  wp_enqueue_script( 'jquery' );
  wp_enqueue_script( 'theme-plugins',get_template_directory_uri() . '/js/plugins.js' ,             array( 'jquery','jquery-ui-draggable','jquery-ui-dialog' ) );
  wp_enqueue_script( 'google-map','http://maps.google.com/maps/api/js?sensor=true',     array( 'jquery','jquery-ui-draggable','jquery-ui-dialog' ) );
  wp_enqueue_script( 'theme-script', get_template_directory_uri() . '/js/script.js', array( 'jquery','jquery-ui-draggable','jquery-ui-dialog' ) );
  wp_enqueue_script( 'ajax', get_template_directory_uri() . '/js/ajax.js', array( 'jquery') );

}    

add_action('init', 'my_theme_scripts');

そして、私の ajax.js ファイルで

jQuery(document).ready(function ($) {

$('#manufacturer,#make_date,#fuel_type,#transmission,#price_from,#price_to').on({
    change: function(){

        $.ajax({
            type: 'POST',
            url: '/wp-admin/admin-ajax.php',
        data: {
            action: 'count_results_cal',
            manufacturer : $("#manufacturer").val(),
            year : $("#make_date").val(),
            fuel : $("#fuel_type").val(),
            transmission : $("#transmission").val(),
            price_from: $("#price_from").val(),
            price_to : $("#price_to").val(),
            body_type : $("#body_type").val(),
            vat : $("#vat").val()
        },
        success: function(data, textStatus, XMLHttpRequest){
            $('#offers_found span').html(data);
        },
        error: function(MLHttpRequest, textStatus, errorThrown){
            alert(errorThrown);
        }
        });
}});

}); 考えられることはすべて試しましたが、結果はありませんでした。誰かアイデアはありますか?

4

1 に答える 1

1

URL を完全なアドレス (http://.../) に変更することで、これを修正しました。

于 2012-08-18T08:05:38.660 に答える