这是我尝试的,但它给控制台错误。我不知道如何运行这个,我已经将jquery变量传递给sql查询,但它不起作用
<小时>
<script type="text/javascript">
var scriptTag = document.scripts[document.scripts.length - 1];
var parentTag = scriptTag.parentNode;
var main = parentTag.parentNode;
var id = jQuery(main).attr(\'id\')
var i;
for (i = id; i<=id; i++) {
<?php
$results = $wpdb->get_var("select COUNT(*) from wpq7_pmpro_memberships_users where user_id = $current_user->ID AND membership_id = ?>id <?php");
if( $results > 0){
?>
if(id == i){
btn = \'<a href="https://thepearledu.com/membership-account/membership-checkout/?level=\'+id+\'" class="elementor-button-link orange-btn elementor-button elementor-size-md" role="button"><span class="elementor-button-content-wrapper"><span class="elementor-button-text">GET IT NOW <font color="#00ff" class="animated infinite flash delay-2s">Only ₹ 99.00 </font></span></span></a>\'
jQuery(\'#\'+id).append(btn)
}
}
<?php } ?>
</script>
<?php
##
我尝试了Ajax,但不幸的是,这也不起作用
<script type="text/javascript">
var scriptTag = document.scripts[document.scripts.length - 1];
var parentTag = scriptTag.parentNode;
var main = parentTag.parentNode;
var id = jQuery(main).attr(\'id\')
var i;
for (i = id; i<=id; i++) {
jQuery.ajax({
type: "POST",
url: "<?php echo admin_url(\'admin-ajax.php\'); ?>",
dataType: "html",
data: {
action: \'my_action_name\',
"myData":id
}}).done(function(data) {
console.log(data);
if(data == true){
btn = \'<a href="https://thepearledu.com/membership-account/membership-checkout/?level=\'+id+\'" class="elementor-button-link orange-btn elementor-button elementor-size-md" role="button"><span class="elementor-button-content-wrapper"><span class="elementor-button-text">GET IT NOW <font color="#00ff" class="animated infinite flash delay-2s">Only ₹ 99.00 </font></span></span></a>\'
jQuery(\'#\'+id).append(btn)
}
else{
btn = \'<a href="https://thepearledu.com/membership-account/membership-checkout/?level=\'+id+\'" class="elementor-button-link orange-btn elementor-button elementor-size-md" role="button"><span class="elementor-button-content-wrapper"><span class="elementor-button-text">GET IT NOW <font color="#00ff" class="animated infinite flash delay-2s">Only ₹ 99.00 </font></span></span></a>\'
jQuery(\'#\'+id).append(btn)
}
});
}
</script>
##
在相同的文件函数中。php
function my_action_name(){
$data = $_POST[\'myData\'];
$results = $wpdb->get_var("select COUNT(*) from wpq7_pmpro_memberships_users where user_id = $current_user->ID AND membership_id = $data");
if( $results > 0){
return true;
}
}