I am trying to split the Ajax response in two separate Div. I am getting the response in a single Div. Please see the code
$(document).ready(function() {
$.post("check.php", {
job: exactdatainner,
attrb: getattr
},
function(data, status) {
alert("Data: " + data + "
Status: " + 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;
?>
I am getting the result but all the result printing inside first div only Here is the PHP code
</div>
You need to echo
out the PHP logic where you want it to appear on the page:
<?php
$job = $_POST['job'];
$attrb = $_POST['attrb'];
?>
<div class="job"><?php echo $job; ?></div>
<div class="attribute"><?php echo $attrb; ?></div>
Or alternatively you can echo
out the HTML components as well:
<?php
$job = $_POST['job'];
$attrb = $_POST['attrb'];
echo "<div class='job'>$job</div>";
echo "<div class='attribute'>$attrb</div>";
?>
You parsed data
with wrong Syntex:
{
job: exactdatainner,
attrb: getattr
}
Just change to this:
{
"job": "exactdatainner",
"attrb": "getattr"
}
Also change the PHP code:
<?php
$job = $_POST['job'];
$attrb = $_POST['attrb'];
echo $job."||";//Add || to seperate Objects
echo $attrb;
?>