<div id="div01">01</div>
<div id="div02">02</div>
<img src="../img/logo.png" onclick="blueSky()"/>
.js
function blueSky() {
$.ajax({
type:'GET',
url: 'test.php',
success: function(respond) {
document.getElementById("div02").innerHTML=respond; // works
}
});
$("#div01").html("<?php echo $target;?>"); } // should be "abc" - doesn't work
测试.php
...
$target = "abc";
$("#div01").html("<?php echo $target;?>"); } // should be "abc" - doesn't work
它不应该工作。因为$target
是在测试中定义的.php并且不在你调用 javascript .html()
的范围内。
你可以做:
$("#div01").html(respond);
在 ajax 调用的 success:
属性内。
另外,在test.php中,我希望您正在做一个echo $target
,以便将"abc"推回blueSky()
函数的respond
对象
你正在使用 AJAX 来获取test.php
,所以你必须这样做:
测试.php
$target = 'abc';
echo $target;
或者这个:
function blueSky() {
<?php include 'test.php'; ?>
$("#div01").html("<?php echo $target; ?>"); }