Javascript ajax调用,检查返回值中的div

Javascript ajax调用,检查返回值中的div,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我有一个“加载更多”按钮,单击时的调用如下所示: $(document).ready(function(){ var pageIndex = 1; $('#loadmorebuilds-div').click(function() { $('#buildcontainer').imagesLoaded( function(){ $.ajax({ url: 'includes/loadmorebuilds.php?type=tr

我有一个“加载更多”按钮,单击时的调用如下所示:

$(document).ready(function(){
    var pageIndex = 1;
    $('#loadmorebuilds-div').click(function() {
        $('#buildcontainer').imagesLoaded( function(){
        $.ajax({
           url: 'includes/loadmorebuilds.php?type=trending&pageIndex=' + pageIndex,
           success: function(html) {
              var el = jQuery(html);
              jQuery("#buildcontainer").append(el).masonry( 'reload' );
              $("#loadmorebuilds-div").stop().fadeOut();
              pageIndex++;
              $("#buildcontainer").masonry()

              rowCount = el.find('#countvar').length;
              if (rowCount <= 7) {
                $("#loadmorebuilds-div").remove();
              }
           }

        });

    });

});
});
$(文档).ready(函数(){
var pageIndex=1;
$('loadmorebuilds div')。单击(函数(){
$(“#buildcontainer”).imagesLoaded(函数(){
$.ajax({
url:'includes/loadmorebuids.php?type=trending&pageIndex='+pageIndex,
成功:函数(html){
var el=jQuery(html);
jQuery(“#buildcontainer”).append(el).mashine('reload');
$(“#loadmorebuilds div”).stop().fadeOut();
pageIndex++;
$(“#buildcontainer”).mashine()
rowCount=el.find('#countvar').length;
如果(rowCount在JS中,.length()返回对象中的字符数。示例:

<div>1111</div> - Will return always 4.
1111-将始终返回4。
而不是

rowCount = el.find('#countvar').length;
if (rowCount <= 7) {
   $("#loadmorebuilds-div").remove();
}
rowCount=el.find('#countvar').length;

如果(rowCount与其他所有行数不同,如果您正确构建了html,那么
el.find('#countvar')).length
将始终返回1或0。我明白了,我被指示使用.length,但我现在明白了。但是,即使结果小于7,它现在也不起任何作用。鉴于.length有效,我可以尝试一种黑客解决方案,将字段设置为空或在php端给它一个值,然后使用.lengthscratch。似乎没有work.必须是其他内容,不能与选择器一起使用。我将返回并检查所有内容。如果它不起作用,请尝试$(“#loadmorebuilds div”).css(“display”,“none”);如果我简单执行,请确保PHP脚本返回准确的值(在浏览器中打开以查看):rowCount=$(“#countvar”).html();alert(rowCount);然后返回div中的内容。但是,只要我做了一个检查,那么if do:if(rowCount=3){alert(rowCount);}那么即使rowCount不是3,它也会发出警报3…是否出于某种原因,var在检查中被设置为3?好的,最后得到了一些有效的结果。如果我删除了数字检查,只做了一个if(rowCount)然后一切都解决了,所以我只需确保div im检查为空或不为空。
<div>1111</div> - Will return always 4.
rowCount = el.find('#countvar').length;
if (rowCount <= 7) {
   $("#loadmorebuilds-div").remove();
}
rowCount = $("#countvar").html(); /* Will return the code inside that object, or the num rows*/
if (rowCount <= 7) {
   $("#loadmorebuilds-div").remove();
}