I'm sending request by $.ajax method from test.php to ajax.php page. The console shows "200 ok" that means the request is ok. But return nothing, although the console doesn't show any error. My used pages are as following:
test.php
<div id="return-data">
<ul class="return-lists">
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$('.submit-form').click(function() {
var name = "tanvir";
var address = "Dhaka";
var cData = "name=" + encodeURIComponent(name) + "&address=" + encodeURIComponent(address);
$.ajax({
url: "ajax.php",
type: "POST",
data: cData,
success: function(data)
{
alert(data);
$('#return-data .return-lists').append(data);
}
});
});
</script>
And ajax.php
<?php
if( isset($_POST['name']) ) {
$name = $_POST['name'];
$address = $_POST['address'];
$lists = '';
$lists .= '<li>' . $name . '</li>';
$lists .= '<li>' . $address . '</li>';
return $lists;
exit;
}
I also have tried by removing if( isset($_POST['name']) ) {} and by using echo instead of return in ajax.php
'.submit-form'a submit button in a form?echoin ajax.php