search

Home  >  Q&A  >  body text

running js code in php

How to run js code in php

1. In this case, ok will not pop up

<?php
session_start();
if($_POST){
    if($_POST['mobile']!=$_SESSION['mobile'] or $_POST['mobile_code']!=$_SESSION['mobile_code'] or empty($_POST['mobile']) or empty($ _POST['mobile_code'])){
        echo '<script type="text/javascript">';
        echo 'alert("ok");';
        echo '</script>';
    }else{
        $_SESSION['mobile'] = '';
        $_SESSION['mobile_code'] = '';

}
?>

2. In this case, you can pop up ok

<?php
        echo '<script language="javascript">';
        echo 'alert("ok");';
        echo '</script>';
?>

Is there any difference between the two? Please tell me, thank you

仅有的幸福仅有的幸福2758 days ago643

reply all(3)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-16 13:09:03

    There is no difference. In the first case, you did not enter the if statement, so there is no pop-up box. You can try removing the outer if ($_POST), and you can pop up the box. I guess you haven't sent a post request at all, so you can't enter the if code block.

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 13:09:03

    Dear, this does not run in php.
    php -> Output html+js -> The browser receives and executes js -> Result

    For your first example, it is the web page returned when making a POST request. Generally, you use a browser to enter the URL, which is a GET request

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-16 13:09:03

    There is no difference if you look at the code alone, but it may be different if you look at the actual situation. Only if it is judged that there is no entry, the pop-up box will not pop up. You should use ajax in JQ. It’s not difficult to check it out on Baidu

    reply
    0
  • Cancelreply