write php inside javascript alert

后端 未结 3 1773
迷失自我
迷失自我 2021-01-22 14:33

I write PHP inside JS in the following way

alert();

echo__(\"Error-login\") correlates with

相关标签:
3条回答
  • 2021-01-22 14:49

    You are missing quotes in the alert() call.

    alert('<?php echo __("Error-login") ?>'); 
    
    0 讨论(0)
  • 2021-01-22 14:54

    Your line becomes

    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.

    0 讨论(0)
  • 2021-01-22 14:57

    try this

    <?php echo '<script language="javascript">confirm("Do you want this?")</script>;'; ?>
    
    0 讨论(0)
提交回复
热议问题