我想用我的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”并且尝试了不同的'和',也是(和)。但似乎没有用。
答案 0 :(得分:0)
你需要将你的javascript传递给php脚本,你可以使用jquery&#39; s 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;
?>