如何 运行 ajax 滚动功能的脚本?

How to run ajax script on scroll function?

滚动时我想要 运行 Ajax 脚本。以下是我要使用的滚动功能和 ajax 脚本。我尝试自己做,但我没有找到任何好的方法。

<script src="https://code.jquery.com/jquery-1.7.2.js"></script>

<script>
$(document).ready(function() {
alert("I am Ready");
$(window).scroll(function() {
alert("I am scrolling");   // I want to use following Ajax here
})
})


function listtitle(){
$.ajax({
type: "POST",
url: "ramesh/index.php",
success:
function(result){
        $( "#ramesh" ).append(result);
    }
});}

</script>

你有 jQuery 作为 $ 吗?

<script>

(function($){
 $(document).ready(function() {
  alert("I am Ready");
  $(window).scroll(function() {
   alert("I am scrolling");   // I want to use following Ajax here
  })
})


 function listtitle(){
 $.ajax({
 type: "POST",
 url: "ramesh/index.php",
 success:
 function(result){
        $( "#ramesh" ).append(result);
 }
 });}
})(jQuery);

</script>

尝试以下操作:

$(document).ready(function() {
    alert("I am Ready");
    $(window).scroll(function() {
        listtitle();        // I want to use following Ajax here. SO I PLACED IT HERE
        alert("I am scrolling");
    });
});


function listtitle() {
    alert("in ajax");
    $.ajax({
        type: "POST",
        async: false, //SO THAT IT WAITS FOR THE LOAD BEFORE CONTINUING
        url: "ramesh/index.php",
        success: function(result) {
            $("#ramesh").append(result);
        }
    });
}