试图早些时候问这个问题,但总是把它弄得一团糟。所以我想我会再试一次,但这一次更清晰。如何使php变量显示在加载的内容
你怎么能得到PHP变量显示在使用JQuery加载的内容?
的index.php:
<!doctype html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script>
$(document).ready(function(){
$('#clickMe').click(function(){
$('#parent').load('loaded.php #child', {},function(){
});
});
});
</script>
</head>
<?php
session_start();
$test = "this should display php string";
$_SESSION['another'] = "Session variable String";
echo ' tests to see if they work below <br>';
echo $test."<br>";
echo $_SESSION['another']."<br><br>";
?>
<button name="clickMe" id="clickMe" class="clickMe">Click me</button>
<div class="parent" name="parent" id="parent" style="background-color:yellow; height:200px; width:200px;">
</div>
<body>
</body>
</html>
loaded.php:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div name="child" id="child" class="child">
<p1> html loads fine..</p1><br>
<?php echo $test ?><br>
<?php echo $_SESSION['another'] ?>
</div>
</body>
</html>
启动会话并定义变量 –
需要从URL中删除'#child'。如果你想要一些特定的返回值,请在请求中使用一个参数,并让请求页面只提供该位。关闭'head'之后还应该有'
'。 – chris85nocked这个快速,生病尝试这些消化有点当im免费:) – bodovix