dtgu21994537 2014-06-27 08:10
浏览 42

在javascript文件中转义<?php ...?>

I'm busy doing server side and client side validation for magento. this validation works fine on server side (php)

on the client side i am using javasrcript.

When i started on this. i had my javascript embedded on a phtml file and everything was working as expected.

because i am using magento so I decided to inject the javascript file via page.xml

When I added the javascript code instead of getting the message pulled I get the php as is.

Here is my javascript:

function DefaultAddressErrorChangeNotAllowedMessage() {
    alert("<?php echo Mage::helper('invent_general')->getDefaultAddressErrorChangeNotAllowedMessage();?>");
    return;
}

I run this when a user hit the onclick it will point to this function DefaultAddressErrorChangeNotAllowedMessage() and the

 <?php echo Mage::helper('invent_general')->getDefaultAddressErrorChangeNotAllowedMessage();?>

will be populated as is.

but when I embed this directly to a phtml file it pull the correct message.

I there a way for javasrcipt that I can use to escape the php and get the correct message which is pulled from config.xml

  • 写回答

3条回答 默认 最新

  • dongtan2017 2014-06-27 08:22
    关注

    PHP is rendered server side only. If you need to "inject" PHP specific values to your javascript, then you either need to render the actual value as part of the output of the php script, or you need to take a new roundtrip to the server, using Ajax.

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭