我正在尝试进行ajax调用,但出现了以下错误:
TypeError: $ is undefined
这是我的职责。php文件:<?php
// Add custom Theme Functions here
//
function gear_guide_product_view( $atts ) {
$a = shortcode_atts( array(
\'id\' => \'0\'
), $atts );
wp_register_script( \'load_product_info\' , \'/wp-content/themes/theme-child/js/test.js\' , array( \'jquery\' ) );
wp_enqueue_script( \'load_product_info\' );
wp_localize_script( \'load_product_info\' , \'para\' , $atts);
}
add_shortcode( \'fsg\' , \'gear_guide_product_view\' );
这是ajax:function load_product_info() {
console.log(para.id);
$.ajax({
type: \'POST\',
url: \'/wp-content/themes/flatsome-child/js/controllers/get_product_info.php\',
data: para,
dataType: \'json\',
success: function (data) {
console.log(data);
}
});
}
load_product_info();
我已经声明了jquery的使用,从我在google上读到的内容来看,这就是我进行ajax调用所需要的一切。如果需要更多信息,请告诉我,我会尽力提供。
谢谢