Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jQuery Ajax无法捕获数据_Php_Jquery_Html_Ajax - Fatal编程技术网

Php jQuery Ajax无法捕获数据

Php jQuery Ajax无法捕获数据,php,jquery,html,ajax,Php,Jquery,Html,Ajax,Add-more-posts.php: ob_start(); //SOME HTML CONTENTS! $contents = ob_get_clean(); if(!empty($contents)){ echo $contents; }else{ echo 'end'; } Index.php中的jQuery: $(document).ready(function(){ $('#get-more').click(function(){ $('#

Add-more-posts.php:

ob_start();
//SOME HTML CONTENTS!
$contents = ob_get_clean();

if(!empty($contents)){
    echo $contents;
}else{
    echo 'end';
}
Index.php中的jQuery:

$(document).ready(function(){
    $('#get-more').click(function(){
        $('#get-more').hide();      
        $('#loading-img').slideDown();
        var post_id = $('div.more').attr('id');
        if(!$("#empty-div").hasClass('ended')){
        $.post("add_more_posts.php", {'post_id': post_id} , function(data){
            if(data == 'end'){
                $("#empty-div").addClass('ended');
                $('.more').remove();
                $('#get-more').hide();
                $('#loading-img').fadeOut();
                $('div#AddPosts').append('Finished Loading!');
            }else{
                if(!$("#empty-div").hasClass('ended')){
                    $('.more').remove();
                    $('#loading-img').remove();
                    $('div#AddPosts').append(data);
                    $('#get-more').show();
                }
            }
        });
    }
    });
});
问题是,它还没有结束。它不是捕获数据=='end',而是将'end'附加到我index.php中的div中


问题出在哪里?

您是否确认在ajax成功中从
数据中获得了什么callback@dakait什么意思?Else{…}部分可以工作…但是如果(data=='end')不工作!当你想执行
数据的内容时,我就是这么说的,因为你正在从服务器返回
$contents
。。。
$contents
包含的内容可能是您想要执行的
如果(数据!=“end”)
$.post("add_more_posts.php", {post_id: post_id} , function(data){