jQuery/Ajax Wordpress分页404错误

jQuery/Ajax Wordpress分页404错误,jquery,ajax,wordpress,pagination,http-status-code-404,Jquery,Ajax,Wordpress,Pagination,Http Status Code 404,我正在制作一个主题,它将允许我的wordpress在页面间切换,而无需使用jQuery重新加载页面 我不确定我做错了什么,但一定是因为我在wordpress中调用新页面的方式,这给了我的JavaScript控制台一个404错误,即使我点击控制台提供给未找到页面的链接,它也会正常加载 我将与您分享我使用的JavaScript代码,以及它在div中加载的页面,因为我非常肯定该页面就是问题所在。如果我尝试使用一些传递的变量创建一个测试PHP文件,它会很好地加载 我的JavaScript: functi

我正在制作一个主题,它将允许我的wordpress在页面间切换,而无需使用jQuery重新加载页面

我不确定我做错了什么,但一定是因为我在wordpress中调用新页面的方式,这给了我的JavaScript控制台一个404错误,即使我点击控制台提供给未找到页面的链接,它也会正常加载

我将与您分享我使用的JavaScript代码,以及它在div中加载的页面,因为我非常肯定该页面就是问题所在。如果我尝试使用一些传递的变量创建一个测试PHP文件,它会很好地加载

我的JavaScript:

function nextpage(page) {

page++;

$('#ajaxloading').text('Loading...');   

$.ajax({
        type: "GET",
        url: homeUrl+"/wp-ajax-post.php?p="+page+"",
        cache: false,
        success: function(html){
            $('#ajaxcontent').html(html);
        }
    });
}
我的wp-ajax-post.php:

<?php
require('wp-blog-header.php');
$wp_query = new WP_Query('paged=' . $_GET['p']); 
?>
<div id="content" style="width:400px;margin:auto;background:#c30000;padding:20px;">

        <?php /* Top post navigation */ ?>

        <?php /* The Loop — with comments! */ ?>
        <?php while ( have_posts() ) : the_post() ?>

        <?php /* Create a div with a unique ID thanks to the_ID() and semantic classes with post_class() */ ?>
                        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <?php /* an h2 title */ ?>
                            <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'hbd-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>

        <?php /* Microformatted, translatable post meta */ ?>
                            <div class="entry-meta">
                                <span class="meta-prep meta-prep-author"><?php _e('By ', 'hbd-theme'); ?></span>
                                <span class="author vcard"><a class="url fn n" href="<?php echo get_author_link( false, $authordata->ID, $authordata->user_nicename ); ?>" title="<?php printf( __( 'View all posts by %s', 'hbd-theme' ), $authordata->display_name ); ?>"><?php the_author(); ?></a></span>
                                <span class="meta-sep"> | </span>
                                <span class="meta-prep meta-prep-entry-date"><?php _e('Published ', 'hbd-theme'); ?></span>
                                <span class="entry-date"><abbr class="published" title="<?php the_time('Y-m-d\TH:i:sO') ?>"><?php the_time( get_option( 'date_format' ) ); ?></abbr></span>
                                <?php edit_post_link( __( 'Edit', 'hbd-theme' ), "<span class=\"meta-sep\">|</span>\n\t\t\t\t\t\t<span class=\"edit-link\">", "</span>\n\t\t\t\t\t" ) ?>
                            </div><!-- .entry-meta -->

        <?php /* The entry content */ ?>
                            <div style="height:50%;overflow-y:auto;" class="entry-content"  id="#ajaxloading">
        <?php the_content( __( 'Continue reading <span class="meta-nav">&raquo;</span>', 'hbd-theme' )  ); ?>
        <?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'hbd-theme' ) . '&after=</div>') ?>
                            </div><!-- .entry-content -->

        <?php /* Microformatted category and tag links along with a comments link */ ?>
                            <div class="entry-utility">
                                <span class="cat-links"><span class="entry-utility-prep entry-utility-prep-cat-links"><?php _e( 'Posted in ', 'hbd-theme' ); ?></span><?php echo get_the_category_list(', '); ?></span>
                                <span class="meta-sep"> | </span>
                                <?php the_tags( '<span class="tag-links"><span class="entry-utility-prep entry-utility-prep-tag-links">' . __('Tagged ', 'hbd-theme' ) . '</span>', ", ", "</span>\n\t\t\t\t\t\t<span class=\"meta-sep\">|</span>\n" ) ?>
                                <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'hbd-theme' ), __( '1 Comment', 'hbd-theme' ), __( '% Comments', 'hbd-theme' ) ) ?></span>
                                <?php edit_post_link( __( 'Edit', 'hbd-theme' ), "<span class=\"meta-sep\">|</span>\n\t\t\t\t\t\t<span class=\"edit-link\">", "</span>\n\t\t\t\t\t\n" ) ?>
                            </div><!-- #entry-utility -->
                        </div><!-- #post-<?php the_ID(); ?> -->

        <?php /* Close up the post div and then end the loop with endwhile */ ?>      
        <?php endwhile; ?>
    <?php pagenavi(); ?>
    </div><!-- #content -->


所以,尽管我在WordPress上显然不是用最“正确”的方式,但多亏了StackOverflow上的另一篇文章,我已经解决了这个问题

问题在于:

require('wp-blog-header.php');
应该是:

include('wp-load.php');

虽然这确实在我的插件中产生了一些全局变量的问题,但我还是能够绕过它。。。我知道这不是在Wordpress中实现ajax的“正确”方法,因为它是内置的,但它对我很有用。

你在这里得到了页码$wp\u query=new wp\u query('paged='。$\u GET['p']);来自请求,但未被使用where@AmitChotaliya,它正在加载页面查询。当我转到wp-ajax-post.php并亲自将这些变量传递到正确的页面时……我研究了使用wp_查询的正确方法,并修改了这一行
,但仍然得到相同的结果