admin管理员组文章数量:1026989
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.
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.
本文标签: Data insertion after clicking a button does not work (scriptAjaxPHP)
版权声明:本文标题:Data insertion after clicking a button does not work (script, AJAX, PHP) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1736720514a1431964.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论