1 - the button "Choice" has Id "ButtonPubVideoHdp" in Elementor
2 - the file wp-content/themes/generatepress/js/wp_ajax_calls.js manages the click and calls in the file wp-content/themes/generatepress/functions.php the'buttonpubvideohdp_insertdata'
jQuery(document).ready(function() {
jQuery("#ButtonPubVideoHdp").click(function () {
console.log('The function is hooked up');
jQuery.ajax({
type: "POST",
url: "/wp-content/themes/generatepress/functions.php",
data: {
action: 'buttonpubvideohdp_insertdata',
},
success: function (output) {
console.log(output);
}
});
console.log('The function is finished');
});
});
3 - the file wp-content/themes/generatepress/functions.php asks the insert in data base via the function buttonpubvideohdp_insertdata(). The php code is inserted in the file functions.php by a plugin
wp_enqueue_script('ajax-calls', get_template_directory_uri() .'/js/wp_ajax_calls.js', array('jquery'), '1.0', true);
// register the ajax action for authenticated users
add_action('wp_ajax_buttonpubvideohdp_insertdata', 'buttonpubvideohdp_insertdata');
// register the ajax action for unauthenticated users
add_action('wp_ajax_nopriv_buttonpubvideohdp_insertdata', 'buttonpubvideohdp_insertdata');
// handle the ajax request
function buttonpubvideohdp_insertdata() {
global $wpdb;
$User_Name = 'Nouveau nom 14h26';
$table_name = $wpdb->prefix . 'Yearbook_test';
echo "Hi everyone";
$wpdb->insert(
$table_name,
array(
'User_Name' => $User_Name,
)
);
echo $wpdb->last_error ;
}
No insert, please help.
1 - the button "Choice" has Id "ButtonPubVideoHdp" in Elementor
2 - the file wp-content/themes/generatepress/js/wp_ajax_calls.js manages the click and calls in the file wp-content/themes/generatepress/functions.php the'buttonpubvideohdp_insertdata'
jQuery(document).ready(function() {
jQuery("#ButtonPubVideoHdp").click(function () {
console.log('The function is hooked up');
jQuery.ajax({
type: "POST",
url: "/wp-content/themes/generatepress/functions.php",
data: {
action: 'buttonpubvideohdp_insertdata',
},
success: function (output) {
console.log(output);
}
});
console.log('The function is finished');
});
});
3 - the file wp-content/themes/generatepress/functions.php asks the insert in data base via the function buttonpubvideohdp_insertdata(). The php code is inserted in the file functions.php by a plugin
wp_enqueue_script('ajax-calls', get_template_directory_uri() .'/js/wp_ajax_calls.js', array('jquery'), '1.0', true);
// register the ajax action for authenticated users
add_action('wp_ajax_buttonpubvideohdp_insertdata', 'buttonpubvideohdp_insertdata');
// register the ajax action for unauthenticated users
add_action('wp_ajax_nopriv_buttonpubvideohdp_insertdata', 'buttonpubvideohdp_insertdata');
// handle the ajax request
function buttonpubvideohdp_insertdata() {
global $wpdb;
$User_Name = 'Nouveau nom 14h26';
$table_name = $wpdb->prefix . 'Yearbook_test';
echo "Hi everyone";
$wpdb->insert(
$table_name,
array(
'User_Name' => $User_Name,
)
);
echo $wpdb->last_error ;
}
No insert, please help.
Share Improve this question edited Dec 11, 2023 at 18:26 Jean-François Moulin asked Dec 11, 2023 at 13:45 Jean-François MoulinJean-François Moulin 11 bronze badge 4- Does the database table exist? – Jacob Peattie Commented Dec 11, 2023 at 13:52
- Yes, the database exists (+table + field). When manually launched, the function buttonpubvideohdp_insertdata() works. – Jean-François Moulin Commented Dec 11, 2023 at 14:04
- Is your console message being logged? What response is returned by the AJAX request? – Jacob Peattie Commented Dec 11, 2023 at 15:08
- Yes the console log is The function is hooked up wp_ajax_calls.js?ver=1.0:3 The function is finished wp_ajax_calls.js?ver=1.0:14 wp_ajax_calls.js?ver=1.0:11 But no response from the AJAX request. – Jean-François Moulin Commented Dec 11, 2023 at 15:54
1 Answer
Reset to default 0Here a screenshot of the log, it is more precise.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1736720516a3908628.html
评论列表(0条)