-1

WordpressのAJAXを介して投稿からコンテンツを取得しようとしています

これがjsの部分です

$("a.ajaxed").click(function(event) {
    event.preventDefault();
    doAjaxRequest();
});
function doAjaxRequest(){
    jQuery.ajax({
        type: 'POST',
        url: ajax_object.ajaxurl,
        data: ({action : 'ajaxify',
            post_id: $(this).attr('id')
            }),
        dataType: 'JSON',
        success:function(data){
            console.log(data.post_title);
        }
    });
}

これはfunctions.phpの部分です

function ajaxify() {
    $post_id = $_POST['post_id'];
    $post_data = get_post($post_id);
    echo json_encode($post_data);
}

console.log(data.post_title)は常にundefinedを表示します。

4

1 に答える 1

0

post_idは未定義でした

$("a.ajaxed").click(function(event) {
    event.preventDefault();     
    $.ajax({
        type: 'POST',
        dataType: 'JSON',
        url: ajax_object.ajaxurl,
        data: ({
            action : 'ajaxify',
            post_id: $(this).parent().attr("id")
            }),
        success:function(data){
            console.log(data);
        }
    });
});
于 2012-08-12T02:47:33.767 に答える