doujiao6116 2017-02-23 21:52
浏览 61

PHP变量在Javascript中不回显[重复]

This question already has an answer here:

This page is a index.html page with javascript in it.

Here is what i am using:

<script>
    $(document).ready(function(){
      var balance ="<?php echo json_encode($balance, JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP); ?>";
      console.log(balance) 

All the console is showing is this:

<?php echo json_encode($balance, JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP); ?>

I have also tried this, since I'm not sure if all those JSON tags are necessary:

var balance ="<?php echo json_encode($balance); ?>";

But it still wont work and just shows up exactly like the others in console:

var balance ="<?php echo "45";); ?>";

Edit: I did not say it was echoing on page but in the console. its a flash file so nothing but the flash was showing on the page. I thought this was a javascript issue i will try the solution below. That other answer may help cause i had not thought of that. Thanks for the solution but i believe this is not the same question

</div>
  • 写回答

1条回答 默认 最新

  • dongyiluan1718 2017-02-23 21:55
    关注

    If your page is .html then will probably not run php on it. Rename to index.php and let me know.

    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发