【发布时间】:2014-11-28 13:14:31
【问题描述】:
test.php
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<script>
function testing(){
$.ajax({
url: 'test.php',
type: 'GET',
data: { va: "answer" },
success: function(data) {
// do something;
alert("answer") ; }
});
}
</script>
<textarea><?php
$compare= $_GET['va'];
echo $compare; ?>
</textarea>
<button onclick="testing();">click</button>
当我单击按钮时收到一条警报消息,但 textarea 中没有任何内容。无法将 javascript 变量导入 php 代码。这里有什么问题?
【问题讨论】:
-
它正在工作,但您没有刷新页面。 Textarea 它在时间 0 渲染。然后您在时间 1 进行 Ajax 调用。Textarea 它已经渲染,所以它没有刷新。
标签: javascript php ajax