Javascript 我想在搜索记录时停止自动滚动?

Javascript 我想在搜索记录时停止自动滚动?,javascript,ajax,html,Javascript,Ajax,Html,在我的索引页面上有自动滚动器,当我搜索他们给出结果的记录时,我在该页面上也有搜索功能。当我向下滚动页面时,会自动添加一条新记录。我想在搜索记录时禁用自动加载程序。有人有主意吗 <script type="text/javascript" language="javascript"> $().ready(function () { $("#hdnStudentCount").val(5); }); function AddStudentRecord() {

在我的索引页面上有自动滚动器,当我搜索他们给出结果的记录时,我在该页面上也有搜索功能。当我向下滚动页面时,会自动添加一条新记录。我想在搜索记录时禁用自动加载程序。有人有主意吗

<script type="text/javascript" language="javascript">
$().ready(function () {
    $("#hdnStudentCount").val(5);
});

function AddStudentRecord() {
           $.ajax({
        type: 'Get',
        url: '/Home/getdeal',
        data: {
            lastdeal: parseInt($("#hdnStudentCount").val()) + 1,
        },

        async: false,
        dataType: "html",
        success: function (data) {
              data = JSON.parse(data);
            for (var i = 0; i < data.length; i++) {

                if (data[i] != '') {
                    $("#studentTemplate").tmpl(data[i]).appendTo("#divMain");
                    var DealID = (data[i]["DealID"]);
                    $("#hdnStudentCount").val(parseInt(DealID));
                    $('div#last_msg_loader').html('<img src="/Images/ajax-loade.gif">');
                }

            }

        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
        }
    });
}

$(window).scroll(function () {

    if ($(window).scrollTop() == $(document).height() - $(window).height()) {
        AddStudentRecord();
    }
});
$('#developer').click(function (e) {
    // do something fancy
    return false; // prevent default click action from happening!
    e.preventDefault(); // same thing as above
});
</script>

$().ready(函数(){
$(“hdnStudentCount”).val(5);
});
函数AddStudentRecord(){
$.ajax({
键入:“Get”,
url:“/Home/getdeal”,
数据:{
lastdale:parseInt($(“#hdnStudentCount”).val())+1,
},
async:false,
数据类型:“html”,
成功:功能(数据){
data=JSON.parse(数据);
对于(变量i=0;i
如果您有一个表单用于搜索,那么页面的url可能会发生一些变化,例如,页面的url可能会发生类似的变化

..…/search?attr_name=value&

您可以检查window.location.href'like中是否有“搜索”

$(window).scroll(function () {

  if ($(window).scrollTop() == $(document).height() - $(window).height() && (window.location.href.indexOf('/search') === -1)) {
      AddStudentRecord();
  }
});
其他 当发送搜索请求时,您可以在窗口对象上设置一些变量,如

window.isSearching=true

如果条件允许,您可以检查该变量

$(window).scroll(function () {

  if ($(window).scrollTop() == $(document).height() - $(window).height() && (typeof(window.isSearching) === 'undefined')) {
      AddStudentRecord();
  }
});