[英]Echo JS variable in Joomla JText
Ajax.php, Script tag in php file Ajax.php,php文件中的脚本标记
<script>
success: function(data) {
var message = data.message; //Json data
if ( data.status == 1 ) {
jQuery("#msgError").html(<?php echo JText::_(' + message + ');?>);
}
}
Is it possible to Echo JS variable in php like above? 是否有可能像上述那样在php中回显JS变量?
Here is a best example, 这是一个最好的例子,
<?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>
I already sent code to merge in joomla to make it more advanced. 我已经发送了要在joomla中合并的代码,以使其更高级。 Please check it here https://github.com/joomla/joomla-cms/pull/6006 Also there are many ways to do it which you will find in above link.
请在这里检查它https://github.com/joomla/joomla-cms/pull/6006还有很多方法可以在上面的链接中找到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.