我怎么能把PHP代码放在js函数中

时间:2015-07-25 19:40:04

标签: javascript php jquery

我怎么能把这段代码

<?php echo "user"; ?>

这个功能

$(function() {
    $('#my-tooltip').tooltipster({
        interactive: true,
        content: 'Loading...',
        contentCloning: false,
        contentAsHTML: true,
        contentAsPHP: true,
        animation: 'fade',
        functionBefore: function(origin, continueTooltip) {
            // we'll make this function asynchronous and allow the tooltip to go ahead and show the loading notification while fetching our data.
            continueTooltip();
            origin.tooltipster('content', 
            '<div class="hovercard"> \n\
            <div> \n\
            <div class="display-pic"> \n\
            <div class="cover-photo"> \n\
            <div class="display-pic-gradient"></div>\n\
            <img src="img/NY.jpg" style="width:370px;height:200px;"> </div>\n\
            <div class="profile-pic"><div class="pic"> \n\
            <span class="chat-img">\n\
            <a href="#"><img src="image/19068919.54b2108777ce0.png" alt="User Avatar" class="img-circle" style="width:98px;height:98px;"></a>\n\
            </span></div>\n\
            <div class="details"> <ul class="details-list"> \n\
            </div></div></div><div class="display-pic-gradient"></div>\n\
            <div class="title-container"> \n\
            <a href="#">Tamil Selvan</a> \n\
            <p class="other-info">   PUT PHP CODE HERE      </p></div>\n\
            <div class="info"><div class="info-inner"> <div class="interactions"> <a href="#" class="btn"><i class="fa fa-user-plus"></i> Add Friend</a> <a href="#" class="btn"><i class="fa fa-user-plus"></i> Add Friend</a> \n\
            <a href="#" class="btn">Follow</a> </div></div></div></div></div>');
        }
    });
});

我想将php代码放在此函数的内容中,但我不知道有人可以帮助我

1 个答案:

答案 0 :(得分:0)

如果上面的函数和php代码都在同一个文件中,那么你可以做一件事,然后将代码放在PUT PHP CODE HERE的地方。

   <?php echo "user"; ?>

但如果不是在同一个文件中,则只有一个选项是在服务器上进行ajax调用并返回代码作为响应并粘贴在那里。

相关问题