我試圖弄清楚我的模式文件如何不顯示我的WP內容,如果我嘗試別的,它最終會達到500(內部服務器錯誤),儘管我已經計算出了情況內部服務器錯誤。這是我的Modal的代碼。當Ajax發起模式時顯示WP內容
<?php include '/wp-blog-header.php'; ?>
<?php $postname = new WP_Query([ 'post_type' => 'causes', 'posts_per_page' => 1, 'p' => $_POST['key'] ]); ?>
<?php while ($postname->have_posts()) : $postname->the_post(); ?>
<div class="uk-modal-dialog">
<a class="uk-modal-close uk-close"></a>
<div class="fetched-data">
this is modal popup
<?php echo $post->post_name; ?>
</div>
</div>
<?php endwhile; wp_reset_postdata(); ?>
雖然如果我用純文本的方式進行操作,它確實會顯示模態。 這是我的Ajax腳本。
$(document).ready(function(){
$('.open-modal').on('click', function(){
var postID = $(this).attr('data-content');
var modal = UIkit.modal(".uk-modal", {center: true, bgclose: false});
if (modal.isActive()) {
modal.hide();
} else {
modal.show();
$.ajax({
type: "POST",
cache: false,
dataType: "json",
url: "wp-content/themes/mytheme/inc/structures/modal/modal-donate.php",
data: { key : postID },
success: function(data) {
$('.uk-modal').html(data);
}
});
}
});
});
注意
我更新樣式文件來看看這個:
<?php
require '../../../../../../wp-load.php';
require '../../../../../../wp-blog-header.php';
echo $postKey = $_POST['key'];
global $post;
$args = array('post_type' => 'causes', 'posts_per_page' => 1, 'p' => $postKey);
$posts = get_posts($args);
?>
<?php foreach ($posts as $post) : setup_postdata($post); ?>
<div class="uk-modal-dialog">
<a class="uk-modal-close uk-close"></a>
<div class="fetched-data">
<p>this is modal popup</p>
<?php the_title(); ?>
</div>
</div>
<?php endforeach; ?>
雖然阿賈克斯錯誤不斷顯示在我的模式。
實際上,即時通訊通過我的'scripts.min.js'調用模態「模式,donate.php發起的Ajax ...雖然我完全放棄了'500(內部服務器錯誤)'雖然阿賈克斯錯誤在模式執行後仍然出現一點延遲 – iMarkDesigns
好吧,我現在在這裏發現了這個問題......我更新'dataType:「json」'到'dataType:「html」',現在它工作正常。 – iMarkDesigns