当我单击一个链接时,我试图创建一个ajax调用,该链接是帖子缩略图,结果应该显示帖子内容。
当我使用管理ajax时。php它工作得很好,但问题是URL无法访问。
这是我的ajaxcall
$.ajax({
//url: admin_url + \'/wp-admin/admin-ajax.php\',
url: href + \'?action=ajax\',
dataType: \'json\',
data: {
//action: \'ajax\',
post_id: post_id
},
success: function(data) {
console.log("Succes");
row.before(\'<div id="case" class="twelve columns omega alpha"></div>\');
$("#case").slideUp(1);
$("#case").html(data).slideDown(speed);
$("#header, #featured, .row").animate({\'opacity\': halfOpacity}, speed);
return false;
},
error: function() {
console.log("Error");
window.location = href;
}
});
这是函数中的php。php function ajax() {
global $wpdb;
global $post;
$id = $_GET[\'post_id\'];
$querystr = "
SELECT $wpdb->posts.*
FROM $wpdb->posts
WHERE $wpdb->posts.ID = $id
";
$post = $wpdb->get_results($querystr);
$response = $post[0]->post_content;
$response = json_encode($response);
header( "Content-Type: application/json" );
echo $response;
exit;
}