I am new to studying jquery.ajax. I want to paste some data from a.php to b.php.
Here is my code:
a.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script language="javascript">
$(document).ready(function () {
var params = "value=" + $('#send').text();
$.ajax({
url:'b.php',
type:'post',
dataType:'html',
data:params,
success:function(data){ $("#result").html($(data).html('#aa')); }
});
});
</script>
<body>
<div id="result"></div>//sometimes the return data is empty, so this part just return: <div="aa"></div>
<div id="send">apple</div>
b.php
<?php
echo '<div id="aa">';
//'.$_REQUEST['value'].' will put in some process here, but sometimes the return data is empty.
echo '</div>';
?>
How and where do I add a judgement, if <div id="aa"></div> is empty, add sorry, there is no result between it
so in a.php, the imformation will show: <div id="result"><div id="aa">sorry, there is no result</div></div>
Thanks.
Change your AJAX call to be: