【问题标题】:Echo JS variable in Joomla JTextJoomla JText 中的 Echo JS 变量
【发布时间】:2015-05-28 01:28:58
【问题描述】:

Ajax.php,php 文件中的脚本标签

<script>
 success: function(data) {
    var message = data.message; //Json data 
    if ( data.status == 1 ) {
      jQuery("#msgError").html(<?php echo JText::_(' + message + ');?>);
    } 
 }

是否可以像上面那样在 php 中回显 JS 变量?

【问题讨论】:

    标签: php jquery ajax joomla


    【解决方案1】:

    这是一个最好的例子,

    <?php
    // In php write following code
    JText::script('COM_HELLOWORLD_MESSAGE');
    
    <script>
    // Using in Javascript like this
    Joomla.JText._('COM_HELLOWORLD_MESSAGE')
    
    // For your example look like
     success: function(data) {
        if ( data.status == 1 ) {
          jQuery("#msgError").html(Joomla.JText._('COM_HELLOWORLD_MESSAGE'));
        } 
     }
    ;
    </script>
    

    我已经发送代码合并到 joomla 中以使其更高级。请在这里查看https://github.com/joomla/joomla-cms/pull/6006 还有很多方法可以在上面的链接中找到。

    【讨论】:

      猜你喜欢
      • 2016-11-20
      • 2012-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-08
      • 2014-09-07
      • 2014-12-12
      • 1970-01-01
      相关资源
      最近更新 更多