0

I've been working with this code, which is originally from: Infinite Scroll Tutorial (though I updated the deprecated sql editted it a bunch)

The problem that I'm having is that the ajax isn't triggering/working. I put in the alert before the $.ajax so that I would know when it triggered, and it's triggering when I hit the bottom of the page(or close to it), like it should. But the ajax isn't producing any information, and I'm not sure why.

emptyk.php:

<script src="../jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(){
    $(window).scroll(function(){
        $('#a1').text($(window).scrollTop());
        $('#a2').text($(window).height());
        $('#a3').text($(document).height());
    }); 


    var page = 1;
    $(window).scroll(function(){
        if($(window).scrollTop() + $(window).height() > $(document).height() - 500) {


            page++;

            var data = {
                page_num: page
            };

            var actual_count = "<?php echo $actual_row_count; ?>";

            if((page-1)* 10 > actual_count){
                //$('#load').show();
            }else{
                alert("Ajax active");
                $.ajax({
                    type: "POST",
                    url: "emptykdata.php",
                    data:data,
                    success: function(res) {
                        $("#result").append(res);
                    }
                });
            }
        }
    });
}); 
</script>
<div id="a1">Wut</div>
<div id="a2">Wut</div>
<div id="a3">Wut</div>
<div id="result"></div>

emptykdata.php

<?php
include '../includes/connect.php';
$requested_page = $_POST['page_num'];
$set_limit = (($requested_page - 1) * 10) . ",10";

$resultstmt = mysqli_prepare($connection, "SELECT * FROM products ORDER BY Mminppu ASC LIMIT $set_limit");
mysqli_stmt_execute($resultstmt);
$result = mysqli_stmt_get_result($resultstmt);
$add = mysqli_num_rows($result);


while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
    $_SESSION['PID'] = $row['PID'];
    include '../includes/baseproductlist.php';
}
//echo $html;
?>

Any ideas?

Update:

I checked the javascript console, and it has the following error message:

GET http://localhost/Triiline2/jquery-1.10.2.min.map 404 (Not Found)
James G.
  • 2,852
  • 3
  • 28
  • 52
  • 2
    Are there any errors in the Javascript console? – Justin Wood Sep 16 '13 at 00:57
  • 1
    check your browsers console/network tab to monitor the request and check what is happening – Arun P Johny Sep 16 '13 at 00:57
  • 1
    is there any output from your php page? – Class Sep 16 '13 at 01:01
  • I don't see any `echo/print` statement to send data back to the browser. – The Alpha Sep 16 '13 at 01:09
  • Sounds like jquery is not properly being imported to your page. – Justin Wood Sep 16 '13 at 01:11
  • 1
    @JamesG. [jQuery's jquery-1.10.2.min.map is triggering a 404 (Not Found)](http://stackoverflow.com/questions/18365315/jquerys-jquery-1-10-2-min-map-is-triggering-a-404-not-found) its more likely just your browser for that error – Class Sep 16 '13 at 01:12
  • @ArunPJohny I'm in the chrome developer tools, and I went to those tabs, and they didn't display any info – James G. Sep 16 '13 at 01:12
  • Can u tell us the actual location of your php file.? Your Ajax is calling a file that might not be on the same directory as your original file – CodeGodie Sep 16 '13 at 01:16
  • Okay, now it's saying "POST http://localhost/Triiline2/midcovers/emptykdata.php 404 (Not Found)" Which is a pretty easy fix on my end. -_- – James G. Sep 16 '13 at 01:16
  • I got this, thanks everybody. This has been a very informative question. I am still often shocked by how many things I know nothing of that I should of learned a long time ago. – James G. Sep 16 '13 at 01:27

1 Answers1

0

I apologize for asking such an obvious question, there is information that I should of known that I did not know. I learned much of what I know about javascript and jquery from w3schools, and apparently they don't teach about developer tools or the javascript console. A quick google search quickly explained to me how to use both of these things in my browser.

My problem was that the file was being looked for in a different folder than I had expected. That was simple to resolve, thanks to all of you who helped.

I also did not have the map file for jquery, but I'm not sure if that was part of the cause of this, or a separate problem. This has now also been resolved.

James G.
  • 2,852
  • 3
  • 28
  • 52