在滚动时,我想运行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>
尝试以下操作:
$(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);
}
});
}
您是否将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>