我尝试在我的子主题中添加自定义表单。我已经阅读了此问题的所有文档,但仍然返回0,这是我的代码
作用php(子主题)
function my_custom_scripts() {
wp_enqueue_script( \'custom-js\', get_stylesheet_directory_uri() . \'/assets/js/custom-child.js\', array( \'jquery\' ),\'\',true );
//the_ajax_script will use to print admin-ajaxurl in custom ajax.js
wp_localize_script(\'custom-js\', \'the_ajax_script\', array(\'ajaxurl\' =>admin_url(\'admin-ajax.php\')));
}
add_action( \'wp_enqueue_scripts\', \'my_custom_scripts\' );
add_action( \'wp_ajax_callbackcity\', \'callbackcity\' );
add_action( \'wp_ajax_nopriv_callbackcity\', \'callbackcity\' );
function callbackcity() {
extract($_POST);
$data = \'tes city - \'.$svalue;
return $data;
wp_die();
//die();
}
自定义子项。js公司
jQuery("#get_city").on("change", function (e) {
e.preventDefault();
jQuery.ajax({
type: \'POST\',
dataType: \'json\',
url: the_ajax_script.ajaxurl,
data: {
\'action\': \'callbackcity\',
\'svalue\': 12
},
success: function(data) {
console.log(data);
},
error: function() {
console.log(\'ERROR\');
}
});
});
有人能告诉我我的代码出了什么问题吗?