0

我已经阅读了 .load() 方法的文档和一些在线资源,但对于我正在构建的应用程序,它不起作用。请注意,我以前从未使用过 .load。

<script type="text/javascript">
$(document).ready(function() {
  $('#next').click(function(e){
    alert("Click"); // this alerts when clicked as expected
    $('#atestimonial').load('testimonial.php', function() {
        alert('Load was performed.');
    });
    return false;
  });
});
</script>

该事件按预期进行。该代码块在 header.php(使用 wordpress)中,而实际的 div #atestimonial 在 sidebar.php 中,因此它位于不同的文件中;这有关系吗?

testimonial.php 里面是这样的:

<?php 
include('testimonialPull.php');
echo "Bahh";
?>

testimonialPull.php

<?php
require_once('../../../wp-blog-header.php');
    query_posts(array(
        'cat' => 4,
        'order' => 'ASC', // ASC
        'orderby' => 'rand',
        'showposts' => 1,
    ));
    $wp_query->is_archive = true; $wp_query->is_home = false;
    if (have_posts()) : while (have_posts()) : the_post();
    the_content();
    endwhile; endif;
?>

如果我删除 testimonialPull 的内容,那么它会正确回显。

这只是在证明 div 中随机发布一个帖子。

实际的 div 和 button 的结构是这样的:

<div id="testimonials">

<div class="tHeading"><h4>Client Testimonials</h4></div>

<div class="atestimonial">
    <?php
    include('testimonial.php');
?>
</div>
<div id="next"><a id="nextC" href="#" return="false">NEXT TESTIMONIAL</a></div><!-- END #next -->

</div><!-- END #testimonials -->

那么,我做错了什么让推荐书没有在.load 的 div 中显示吗?

感谢您花时间阅读本文。

快速编辑

这是在本地主机上工作的;我刚刚读到这不适用于 localhost,这是正确的吗?

4

1 回答 1

2

您要求 jQuery 填充$('#atestimonial'),这是一个 id 为atestimonial但您的页面中没有此类元素的元素。

代替

<div class="atestimonial">

经过

<div id="atestimonial">

编辑 :

通过阅读您的评论,我认为您可能遇到路径问题,具体取决于您包含脚本的位置。

代替

$('#atestimonial').load('testimonial.php', function() {

你可能需要类似的东西

$('#atestimonial').load('/testimonial.php', function() {

或者

$('#atestimonial').load('/ggg/testimonial.php', function() {
于 2012-09-14T09:41:49.790 回答