将PHP var设置为javascript结果

set php var as javascript results

本文关键字:javascript 结果 设置 PHP var      更新时间:2023-09-26

我想用我的javascript结果来设置一个php变量。

<script>
var hello;
hello = "ilovetuna.php";
</script>

 <?php
    $variable = "<script>document.write(hello);</script>";
?>

<?php
require('simple_html_dom.php');
$html = file_get_html($variable);
echo $html;
?>

警告:file_get_contents(document.write(hello);):打开流失败

有人知道怎么处理这个吗?谢谢你

ps:我试过在"之前使用' string,也试过不同的"answers",也(和)。

您需要将javascript传递给php脚本,您可以使用jquery的ajax

api.jquery.com/jQuery.ajax

    var hello;
    hello = "ilovetuna.php";
    $.ajax({  
      type: "POST",  
      url: "yourphpscript.php",  
      data: hello,  
      success: function() {  
        alert("it works");
      }  
    });  

在PHP中使用$_POST['data'];检索变量。

<?php
    $variable = $_POST['data'];
?>

<?php
    require('simple_html_dom.php');
    $html = file_get_html($variable);
    echo $html;
?>