通过AJAX的函数调用无法解决这个问题?

时间:2014-01-13 作者:mathiregister

在我的标题中。php文件我有…

<script type="text/javascript">
    var ajaxurl = "<?php echo admin_url( \'admin-ajax.php\', \'relative\' );?>";
</script>
在我的功能中。php文件我有…

add_action(\'wp_ajax_get_event_list\', \'get_event_list\');
add_action(\'wp_ajax_nopriv_get_event_list\', \'get_event_list\');

function get_event_list( $latest = true, $order = \'ASC\', $return = false, $year = NULL, $cat = NULL ) {

    // Stuff of the function

}
在我的脚本中。js文件我有…

$(\'#year-filter .inactive\').click(function(e) {
    e.preventDefault();
    console.log(ajaxurl); // http://mydomain.com/wp-admin/admin-ajax.php 

    $.ajax({
        type: \'GET\',
        url: ajaxurl,
        data: { 
            action: \'get_event_list\',
            year: \'2012\', //param year
            cat: \'vortraege\' //param category
        },
        dataType: \'html\',
        timeout: 300,
        success: function(data){
            console.log(\'Ajax success\');
        },
        error: function(xhr, type){
            console.log(\'Ajax error\');
            console.log(xhr + " " + type)
        }
    });
});
我当前在控制台中遇到以下错误

http://mydomain.com/wp-admin/admin-ajax.php

Ajax错误

[对象XMLHttpRequest]超时

0 个回复
结束