AJAX POST 500 内部服务器错误

AJAX POST 500 INTERNAL SERVER ERROR

我刚刚为我的 wordpress 博客创建了无限循环,它在我的本地 PC(WAMP)上工作得很好,但是当我把它放到网上(nginx 服务器)时它显示 POST http://www.siteurl.com/infinite-loop.php 500 Internal Server Error

Infinite_loop.php

<?php

$infinite_loop= $_POST['pcount']; ?>

<?php require_once("/wp-blog-header.php"); ?>

  <div class="x-container-fluid max width main">
    <div class="offset cf">
      <div class="<?php x_main_content_class(); ?>" role="main">
            <?php
                    global $wpdb;
                    $args = array( 'posts_per_page' => 10, 'order' => 'DESC', 'offset'=>$infinite_loop );    
                    $myposts = get_posts( $args );
                    foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
                    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>


                        <div>
                            <div style="width:300px; float:left;"> 
                                <?php x_ethos_featured_index(); ?> 
                            </div>
                            <div style="width:500px; float:right;">
                                <?php /* print $args['offset']; */ ?>
                                <?php x_get_view( 'ethos', '_content', 'post-header' ); ?>
                                <?php x_get_view( 'global', '_content' ); ?>
                                <?php


                            </div>
                         </div>
                    </article>
                    <?php endforeach; 
                                wp_reset_postdata(); ?>


</div>      <?php get_sidebar(); ?>
</div></div>

AJAX 在主题中 HEADER

<script>
$(document).ready(function() {

var post_page_count = 10;
var height_scroll = 400;
    $(window).scroll(function() {

    if ($('body').height() <= ($(window).height() + $(window).scrollTop())){
        post_page_count = post_page_count+10;

        $.ajax({
            type: "POST",
            async: false,
            url: "theme/infinite_loop.php",
            data: {pcount:post_page_count},
            success:
                function(result){


                    $("#gizinfi").append(result);
                    }
        });
        };
});
});
</script>

我不知道是什么问题。它在带有 WAMP 的本地 PC 上运行良好,但在在线服务器上显示错误。谁能帮我知道问题出在哪里?请帮助...

对于最佳 WordPress 实践,您应该使用 WordPress 的 ajax functions。将其放入您的主题 functions.php 文件

<?php

    add_action( 'wp_ajax_my_inifinte_loop', 'my_inifinte_loop' );
    add_action( 'wp_ajax_my_inifinte_loop', 'my_inifinte_loop' );

    function my_inifinte_loop() {

        $infinite_loop= $_POST['pcount']; 

        ?>

          <div class="x-container-fluid max width main">
            <div class="offset cf">
              <div class="<?php x_main_content_class(); ?>" role="main">
                    <?php
                            global $wpdb;
                            $args = array( 'posts_per_page' => 10, 'order' => 'DESC', 'offset'=>$infinite_loop );    
                            $myposts = get_posts( $args );
                            foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
                            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>


                                <div>
                                    <div style="width:300px; float:left;"> 
                                        <?php x_ethos_featured_index(); ?> 
                                    </div>
                                    <div style="width:500px; float:right;">
                                        <?php /* print $args['offset']; */ ?>
                                        <?php x_get_view( 'ethos', '_content', 'post-header' ); ?>
                                        <?php x_get_view( 'global', '_content' ); ?>
                                        <?php


                                    </div>
                                 </div>
                            </article>
                            <?php endforeach; 
                                        wp_reset_postdata(); ?>


              </div>      <?php get_sidebar(); ?>
            </div>
        </div>

        <?php


        die();

    }

?>

比更新你的 javascript 到

<script>
$(document).ready(function() {

var post_page_count = 10;
var height_scroll = 400;
    $(window).scroll(function() {

        if ($('body').height() <= ($(window).height() + $(window).scrollTop())){
            post_page_count = post_page_count+10;

            $.ajax({
                type: "POST",
                async: false,
                url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
                data: {
                    pcount:post_page_count,
                    action: 'my_inifinte_loop'
                },
                success:
                    function(result){
                        $("#gizinfi").append(result);
                    }
            });
        };
    });
});
</script>

我找到了解决方案... 这是一个wordpress问题 Wordpress header 设置为允许外部插件样式开发。 我包含的 header 不正确,这就是我收到 404 和 500 错误的原因。

我改变那个

<?php require_once("/wp-blog-header.php"); ?>

require('/wp-config.php');
 $wp->init();
 $wp->parse_request();
 $wp->query_posts();
 $wp->register_globals();