简体   繁体   English

如何将$ username变量回显到javascript中

[英]How to echo $username variable into a javascript

I was wondering if there is a way to display or echo a $username variable within a javascript function that display an html string. 我想知道是否有一种方法可以显示或回显显示html字符串的javascript函数中的$username变量。 This is the original function: 这是原始功能:

    Plugin.prototype.counter = function() {
    if (this.s.counter) {
    $(this.s.appendCounterTo).append('<div id="counter"><span id="counter-current">' 
        + (parseInt(this.index, 10) + 1) + '</span> / <span id="counter-all">' 
        + this.$items.length 
        + '</span><a href="index.htm"><sig> JOHN SMITH </sig><img src="jOHN.png"></a></div>');
    }
};

I've tried inserting this: 我试过插入此:

    <?php $arrays = file_get_contents('username.txt'); echo $arrays;?>

Instead of JOHN SMITH , with and without quotes... Not working. 而不是JOHN SMITH ,带或不带引号。

Any idea how to do such task? 任何想法如何做这样的任务?

Taking a wild guess here, it's possible your file is being called incorrectly. 在这里大胆猜测,可能是您的文件被错误地调用。

This will specify the absolute path on the server. 这将指定服务器上的绝对路径。

<?=file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/username.txt');?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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