jQuery Ajax returning 404 Error, but correct Response

后端 未结 6 1536
既然无缘
既然无缘 2020-12-01 18:07

I\'m posting some data to a PHP script via jQuery AJAX, and everything executes correctly, but it returns a 404 error. In my Firebug console the response from the PHP scrip

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 18:17

    No one else posted this as an answer, so it's worth noting. You should be including wp-load.php instead of wp-blog-header.php.

    If you open up wp-blog-header.php you'll see why:

    if ( !isset($wp_did_header) ) {
    
        $wp_did_header = true;
    
        require_once( dirname(__FILE__) . '/wp-load.php' );
    
        wp();
    
        require_once( ABSPATH . WPINC . '/template-loader.php' );
    
    }
    

    If you are only outputting json for an AJAX operation, you do not need to include template-loader.php. This will create unnecessary overhead, and then of course provide the 404 error.

    This 'workaround' is necessary for current and future versions of WordPress. I'm assuming anything past 3.0 should include wp-load.php as stated.

提交回复
热议问题