Javascript jqueryajax永远不会成功。错在哪里?

Javascript jqueryajax永远不会成功。错在哪里?,javascript,php,jquery,ajax,wordpress,Javascript,Php,Jquery,Ajax,Wordpress,我正在尝试为使用Wordpress的php服务器制作一个ajax。 我使用重写规则重定向ajax调用: function Ajax_roules_setup(){ add_rewrite_rule( 'ajax/([^/]*)', 'index.php?action=$matches[1]', 'top' ); } 添加动作('init','Ajax\u roules\u setup') 这

我正在尝试为使用Wordpress的php服务器制作一个ajax。 我使用重写规则重定向ajax调用:

function Ajax_roules_setup(){
        add_rewrite_rule(
            'ajax/([^/]*)',
            'index.php?action=$matches[1]',
            'top'
        );
}
添加动作('init','Ajax\u roules\u setup')

这很好(如果我转到localhost/wordpress/ajax/myrequest,我会得到包含请求的页面)

现在我有了管理ajax请求的php代码:

<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

function load_template_part($template_name, $part_name=null) {
    ob_start();
    get_template_part($template_name, $part_name);
    $var = ob_get_contents();
    ob_end_clean();
    return $var;
}

$reply = null;
switch ($wp->query_vars['action']){
    case 'get-more-posts':
        $html_for_ajax = sprintf('%s',  load_template_part("content","fourFrom"));
        $reply = 
            array(
                'status' => 'success',
                'last'   => ''.$all_post_loaded,
                'html'   => $html_for_ajax ,
            );
        break;
}

print_r(json_encode($reply));
?>
因此,据我所知,这应该是可行的,但所有的调用都以错误404结束,没有找到!
可能是永久链接的问题,或者是其他问题?

它是
成功
而不是
成功

尝试:-

success: function (result) {
                                    //var reply = jQuery.parseJSON(result);
                                    if (reply.last) {
                                        calls = -1;
                                        jQuery("#forntPage-getMore").remove;
                                    } else {
                                        calls++;
                                    }
                                    jQuery("#frontpage-post-grid").append(reply.html);
                                }, error: function (xhr, status, error) {
                                    var err = eval("(" + xhr.responseText + ")");
                                    alert(err.Message);
                                }

它是
成功
而不是
成功

尝试:-

success: function (result) {
                                    //var reply = jQuery.parseJSON(result);
                                    if (reply.last) {
                                        calls = -1;
                                        jQuery("#forntPage-getMore").remove;
                                    } else {
                                        calls++;
                                    }
                                    jQuery("#frontpage-post-grid").append(reply.html);
                                }, error: function (xhr, status, error) {
                                    var err = eval("(" + xhr.responseText + ")");
                                    alert(err.Message);
                                }

Yhea是这样的,现在让我为失去3小时的生命而独自哭泣吧,因为它发生了很高兴帮助@MaGiiKwith every@MaGiiK:)Yhea是这样的,现在让我为失去3小时的生命而哭泣吧,因为它发生了很高兴帮助@MaGiiKwith every@MaGiiK:)