search

Home  >  Q&A  >  body text

Help js code mixed with php code usage exception

How to call the php function in js, js passes in the variable, and the php function returns it to the js variable after processing. I can't read what I wrote. , error report,. It's OK to apply script to PHP, but it won't work if you apply script to PHP. . Specifically, I want to know how to directly transfer variables

<script> var a="1001"; var op='666'; od="<?php $b=op; echo jia($b) ; a variable: '.$b; function jia($c){ //$c="<script>document.write(op)</script>"; return $c.'---8888'; } ?>

sunsun827 days ago1142

reply all(8)I'll reply

  • sun

    sun2022-08-21 15:23:01

    <script>

    var a='1001';

    var op='666';

    od="<?php $bb=' 888'; $b='<script>document.write(op)</script>'; echo jia($b);

    ##</script><?php                                                                                                                 ';

    echo 'a variable:'.$b;

    function jia($c){

    return $c.'---8888';

    }

    ?>

    I mainly want to get the js variables in js and return them after execution in php. . .

    reply
    0
  • autoload

    When php is executed, only the code inside will take effect. The code outside the tag cannot be obtained. You can submit the data to this page through JS, pass the variables to php, php will process it, and then pass it out.

    autoload · 2022-08-21 15:31:36
  • autoload

    autoload2022-08-21 15:22:58

    If you want to pass a value, you can use session

    reply
    0
  • autoload

    autoload2022-08-21 15:15:35

    As I told you, the PHP code is executed first

    image.png

    The op variable is not defined in PHP

    reply
    0
  • sun

    var a='1001'; var op='666'; od=""; document.write(od); I mainly want to execute the js variable agricultural loan php in js and return it. . .

    sun · 2022-08-21 15:20:36
  • autoload

    autoload2022-08-21 13:34:53

    Parse PHP first, then parse JS

    reply
    0
  • sun

    Sir, can you help me see where I made a mistake here? Can it be used if I correct it?

    sun · 2022-08-21 13:35:53
    autoload

    Why don't you format your code? I can't understand it.

    autoload · 2022-08-21 15:10:08
  • Cancelreply