WordPress 中的 Ajax - 无法获取变量
尝试将帖子 ID 从 jQuery 传输到 PHP,但没有成功...
可以在有效负载中看到变量(Chrome 中的 webtools),但无法在 PHP 中获取变量,
如果有人可以提供帮助 - 我将非常感激:)
jQuery:
$("a.uc_more_btn.btn_reg").click(function(){
var post_id = $(this).attr("data-id");
$.ajax({
type: 'post',
url: '/wp-admin/admin-ajax.php',
data: {
'action': 'get_the_ifarme',
'pop_post_id' : post_id
},
success: function(data) {
console.log("Happy");
}
});
});
PHP:
function get_the_ifarme() {
if(isset($_REQUEST['pop_post_id'])){
$pop_post_id = $_REQUEST['pop_post_id'];
$iframe_link = get_field("tour_register_link", $pop_post_id);
echo '<iframe src="'.$iframe_link.'" height="820"></iframe>';
}
}
add_shortcode( 'tickets_iframe', 'get_the_ifarme');
add_action( 'wp_ajax_get_the_ifarme', 'get_the_ifarme' );
add_action( 'wp_ajax_nopriv_get_the_ifarme', 'get_the_ifarme' );
此函数也需要是短代码,因为 iframe 将放置在 Elementor 弹出窗口中。
Trying to transfer post ID from jQuery to PHP, without success ...
Can see the variable in the payload (webtools in Chrome), but can't get the variable in PHP,
If anyone can help - I would be very grateful :)
jQuery:
$("a.uc_more_btn.btn_reg").click(function(){
var post_id = $(this).attr("data-id");
$.ajax({
type: 'post',
url: '/wp-admin/admin-ajax.php',
data: {
'action': 'get_the_ifarme',
'pop_post_id' : post_id
},
success: function(data) {
console.log("Happy");
}
});
});
PHP:
function get_the_ifarme() {
if(isset($_REQUEST['pop_post_id'])){
$pop_post_id = $_REQUEST['pop_post_id'];
$iframe_link = get_field("tour_register_link", $pop_post_id);
echo '<iframe src="'.$iframe_link.'" height="820"></iframe>';
}
}
add_shortcode( 'tickets_iframe', 'get_the_ifarme');
add_action( 'wp_ajax_get_the_ifarme', 'get_the_ifarme' );
add_action( 'wp_ajax_nopriv_get_the_ifarme', 'get_the_ifarme' );
This function also needs to be a shortcode because the iframe will be placed in Elementor pop-up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 $_POST['pop_post_id'] 访问它。
Try access it using $_POST['pop_post_id'].