admin管理员组文章数量:1330599
I write PHP inside JS in the following way
alert(<?php echo __("Error-login") ?>);
echo__("Error-login")
correlates with an xml to translate in two languages with symfony, but now it does not work.
How do I fix this?
I write PHP inside JS in the following way
alert(<?php echo __("Error-login") ?>);
echo__("Error-login")
correlates with an xml to translate in two languages with symfony, but now it does not work.
How do I fix this?
Share Improve this question edited Mar 9, 2012 at 10:21 sarnold 104k23 gold badges185 silver badges243 bronze badges asked Mar 9, 2012 at 9:46 SimonSimon 372 silver badges6 bronze badges 2-
add
;
in'<?php echo __("Error-login"); ?>'
– mgraph Commented Mar 9, 2012 at 9:48 - I hope php code in js works, only if the corresponding file name is saved as a .php file. – shasi kanth Commented Mar 3, 2015 at 12:23
3 Answers
Reset to default 4You are missing quotes in the alert()
call.
alert('<?php echo __("Error-login") ?>');
Your line bees
alert(Error-login);
As you can see, you are missing the quotes:
alert('Error-login');
If somebody uses quotes in the translation, this will also generate an error:
alert('Error's are here');
So you need to escape single quotes before you pass it to Javascript.
try this
<?php echo '<script language="javascript">confirm("Do you want this?")</script>;'; ?>
本文标签: write php inside javascript alertStack Overflow
版权声明:本文标题:write php inside javascript alert - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742271198a2444333.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论