0
我试图得到一个Ajax函数与wordpress一起工作,总是得到默认结果。 我在的functions.php(其他功能旁)WordPress的AJAX无法让它工作总是返回0
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);
}
});
}});
}); 我试过了所有我能想到的没有结果的东西。有没有人有一些想法?