简体   繁体   中英

How to append add php conditions while replacing html text in jquery

basically , when document is ready , I would like to replace the td content with this html content that has some php conditions in it as shown below , but it's not working

<?php
 echo "<script type='text/javascript'>";
 echo "$(document).ready(function(){";
 ?>
 $('#redeem_freebie).html('<a class="btn" <? if (!$freebies->expired) {?>onclick="applyFreebieNow('<?=addslashes($dialog_copy)?>','<?=addslashes($freebies->get_started_link)?>','<?=$freebies->promo_code_id?>');"<? } ?> style="<?=$freebies->expired ? 'cursor: default;':''?>">Redeem Freebie &gt;&gt;</a>');
<?php 
 echo "});";    
 echo "</script>";
 echo "}";

?>
<script type='text/javascript'>
$(document).ready(function(){
    $('#redeem_freebie').html('<a class="btn" <?php if (!$freebies->expired) {?>onclick="applyFreebieNow('<?php echo addslashes($dialog_copy); ?>','<?php echo addslashes($freebies->get_started_link)?>','<?php echo $freebies->promo_code_id?>');"<?php } ?> style="<?php echo $freebies->expired ? 'cursor: default;':''?>">Redeem Freebie &gt;&gt;</a>');
 });   
 </script>

Some hint : dont use <?= really not clear and your error was here <? } ?> <? } ?> <- php short tag

If you want to use some php function when document is ready, you can call an other php page using ajax.

example in jQuery :

$.ajax({
        url: 'yourpagewithfunction.php',
        type: "POST",
        data : {variable : value}
    }).done(function(msg) {
            alert(msg);
});

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM