How to pass value JavaScript variable to PHP?

后端 未结 4 1156
借酒劲吻你
借酒劲吻你 2021-01-22 13:38

Passing value JavaScript variable to PHP.

Example

JavaScript

Var ffffd=\'aaaa\'

PHP

<         


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

    I have tested the following code and it have worked. So please test this code:

    function aa()
    {
        var ffffd='aaaa';
        window.location.href="newpage.php?Result=" +ffffd;
    }
    

    click a button then will call aa() function and will go newpage.php where we get ffffd variable value in Result variable

    newpage.php:

    extract($_GET);
    echo $Result;
    
    0 讨论(0)
  • 2021-01-22 14:23

    One way you can do that is to put it in the cookie:

    var ffffd = 'aaaa';
    document.cookie = "ffffd="+ffffd; // the ffffd in the "" is the name of the cookie
    

    PHP

    $ffffd = $_COOKIE['ffffd'];
    if (ffffd == "aaa") { do something... }
    
    0 讨论(0)
  • 2021-01-22 14:24

    In JS:

     $.post('ajax.php',{'ffffdd' : ffffdd}, function(data){
     });
    

    In PHP

     if(isset($_POST['ffffdd'])) $ffffdd = $_POST['ffffdd'];
    
    0 讨论(0)
  • 2021-01-22 14:32

    Javascript is a Client side scripting language that is only executed after the page is fully loaded. PHP on the other hand is an on-demand compiling script. It parses the PHP within the file and outputs the resulting HTML to the user's Browser.

    0 讨论(0)
提交回复
热议问题