我正在尝试将Ajax响应分为两个单独的Div。我在一个Div中得到响应。请查看代码
$(document).ready(function() {
$.post("check.php", {
job: exactdatainner,
attrb: getattr
},
function(data, status) {
alert("Data: " + data + "\nStatus: " + status);
var obj = data.split('||');
$(".job").html(obj[0]);
$(".attribute").html(obj[1]);
});
});
<div class="job"></div>
<div class="attribute"></div>
<?php
$job = $_POST['job'];
$attrb = $_POST['attrb'];
echo $job;
echo $attrb;
?>
我正在获取结果,但所有结果仅在first div内打印这是PHP代码
答案 0 :(得分:0)
您需要echo
找出要显示在页面上的PHP逻辑位置:
<?php
$job = $_POST['job'];
$attrb = $_POST['attrb'];
?>
<div class="job"><?php echo $job; ?></div>
<div class="attribute"><?php echo $attrb; ?></div>
或者,您也可以echo
删除HTML组件:
<?php
$job = $_POST['job'];
$attrb = $_POST['attrb'];
echo "<div class='job'>$job</div>";
echo "<div class='attribute'>$attrb</div>";
?>
答案 1 :(得分:0)
您使用错误的Syntex解析了data
:
{
job: exactdatainner,
attrb: getattr
}
只需更改为此:
{
"job": "exactdatainner",
"attrb": "getattr"
}
还更改 PHP 代码:
<?php
$job = $_POST['job'];
$attrb = $_POST['attrb'];
echo $job."||";//Add || to seperate Objects
echo $attrb;
?>