Reputation: 455
I have created a jquery function and I tried to run a condition of if the data is false then load more button will not show but when I tried the if condition is not working please can you let me know where and what mistake I am doing ?
function loadmore() {
var count_data = $('#count_data').val();
$(document).ajaxStart(function() {
$('#wait').css('display', 'block');
});
$(document).ajaxComplete(function() {
$('#wait').css('display', 'none');
});
$.ajax({
type: 'POST',
url : 'includes/get_data.php',
data : {count_data : count_data, method: 'count'},
dataType: 'text',
success : function(data) {
if(data == 'No Post Found') {
$('#loadmore').css('display', 'none');
} else {
$('#container_masonry').append(data);
var total_count = parseInt(count_data) + parseInt(6);
document.getElementById('count_data').value = total_count;
}
}
});
}
Here is my php code
$count = $_POST['count_data'];
$limit = 6;
$sql = mysqli_query($connection, "SELECT * FROM models ORDER BY ID ASC LIMIT $count, $limit");
$i = 1;
if(mysqli_num_rows($sql) > 1) {
echo "Data found";
} else {
echo "No Post Found";
}
I would appreciate you suggestions and answers that could help me out
Upvotes: 1
Views: 137
Reputation: 391
Can you please try with exit so it will not output anything else after your actual output. EX: echo "Data found";exit; and echo "No Post Found";exit;
Upvotes: 1