I'm doing an infinite scroll with jQuery, AJAX and PHP. I have all the code and it does not give me any error, but it only gives me an error when I try to access the multimedia files for the scroll data, could there be an error in my code?
jQuery:
<div class="col-md-10 col-sm-12 offset-md-1 mb-4 results">
</div>
<script type="text/javascript">
var start = 0;
var limit = 5;
var reachedMax = false;
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height())
getData();
});
$(document).ready(function () {
getData();
});
function getData() {
if (reachedMax)
return;
$.ajax({
url: 'publicaciones.php',
method: 'POST',
dataType: 'text',
data: {
getData: 1,
start: start,
limit: limit
},
success: function(response) {
if (response == "reachedMax")
reachedMax = true;
else {
start += limit;
$(".results").append(response);
}
}
});
}
</script>
PHP:
<?php
if(isset($_POST['getData']))
{
include ('../conexion.php');
$start = mysqli_real_escape_string($conexion,$_POST['start']);
$limit = mysqli_real_escape_string($conexion,$_POST['limit']);
$consulta = mysqli_query($conexion, "SELECT * FROM publicaciones ORDER BY id_pub DESC LIMIT $start, $limit");
if(mysqli_num_rows($consulta) > 0)
{
$response = "";
while($data = mysqli_fetch_array($consulta)) {
$response .= "
<div class='card mt-3 border-0 rounded-0'>
<div class='card-body'>
<div class='row'>
<div class='col-sm-2'>
<div class='img-user rounded-circle'>
<img class='img-fluid-pub' src='../avatars/".$data['avatar']."' alt='User Image'>
</div>
</div>
<div class='col-sm-10'>
<h3 class='text-muted' onclick='location.href='perfil.php?id='".$data['id']."'>".$data['usuario']."</h3><h3>Seguir</h3>
<p>".$lista['fecha']."</p>
<p>".$lista['titulo']." Me gusta</p>
<p id='descripcion'>".$lista['descripcion']."</p>
<p class='leermas' onclick='leerMas(this);'>Leer más...</p>
<video controls>
<source src='../anadir-publicacion/publicaciones/".$lista['video']."' type='video/mp4'>
Your browser does not support HTML5 video.
</video>
<p>Kcal: ".$lista['kcal']." CarbHid: ".$lista['carbohidratos']." Prot: ".$lista['proteinas']." Gras: ".$lista['grasas']." Tiempo: ".$lista['tiempo']." Personas: ".$lista['personas']." Dinero aprox: ".$lista['precio']."€ Categoría: ".$lista['categoria'];"</p>
</div>
</div>
</div>
</div>
";
}
exit($response);
}
else
exit('reachedMax');
}
?>