i was done adding this script into \\mythemes\\functions.php :
// FGI CODE started
function my_scripts_method() {
// register your script location, dependencies and version
wp_register_script('custom_script',
get_template_directory_uri() . '/js/javascript_.js',
array('jquery'),
'1.0' );
// enqueue the script
wp_enqueue_script('custom_script');
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
wp_enqueue_script('jquery');
// FGI CODE ended
and also my jQuery script which is located under \\mythemes\\js\\javascript_.js :
(function($) {
$(document).ready(function() {
$("#pilih_bulan").change(function() {
alert('a');
});
})
})(jQuery);
actually my purpose is making a combobox with an ID of : #pilih_bulan always trigger some ajax function each time user change the selection (dropdown items).
And the above code (using alert code) is working fine. Unfortunately, when I changed into this below code, it doesn't work at all. Any ideas?
(function($) {
$(document).ready(function() {
$("#pilih_bulan").change(function() {
$.ajax({
method: "POST",
url: "./another_processor.php",
data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
});
})
})(jQuery);
Use the below script and why you used wp_enqueue_script('jquery');
please check your source code jquery must be already added
<?php
function my_scripts_method() {
wp_enqueue_script(
'custom-script',
get_stylesheet_directory_uri() . '/js/custom_script.js',
array( 'jquery' )
);
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.