删除ajax加载的数据,在点击时修改代码并再次加载

时间:2017-06-17 13:48:06

标签: javascript php jquery sql ajax

所以我有一些滚动加载函数的数据,它加载div中的所有sql表行,我正在尝试创建一个选项来过滤它加载的内容。

所以我有默认的load_more.php加载所有行,另一个load_ph.php只加载艺术家类型的摄影师。

我尝试将php文件设置为变量,然后在单击摄影师div时将该变量更改为load_ph.php,但它不起作用

这是我添加的内容

$( "#ph" ).click(function() {
  fetch = 'fetch_ph.php';
  $( ".feed_item" ).detach();
  load_contents(1);
})

完整脚本

var track_page = 1; //track user scroll as page number, right now page number is 1
var loading  = false; //prevents multiple loads
var fetch = 'fetch_pages.php';
load_contents(track_page); //initial content load

$(".feed_headmk").hide();
$(".feed_headph").hide();

$(window).scroll(function() { //detect page scroll
    if($(window).scrollTop() + $(window).height() >= $(document).height()) { //if user scrolled to bottom of the page
        track_page++; //page number increment
        load_contents(track_page); //load content
    }
});
//Ajax load function
function load_contents(track_page){
    if(loading == false){
        loading = true;  //set loading flag on
        $('.loading').show(); //show loading animation
        $.post( fetch, {'page': track_page}, function(data){
            loading = false; //set loading flag off once the content is loaded
            if(data.trim().length == 0){
                //notify user if nothing to load
                $('.loading').html("");
                return;
            }
            $('.loading').hide(); //hide loading animation once data is received
            $("#feed").append(data); //append data into #results element

        }).fail(function(xhr, ajaxOptions, thrownError) { //any errors?
            alert(thrownError); //alert with HTTP error
        })
    }
}

$( "#ph" ).click(function() {
  fetch = 'fetch_ph.php';
  $( ".feed_item" ).detach();
  load_contents(1);
})

0 个答案:

没有答案