我已阅读.load()方法的文档和一些在线资源,并且我构建的应用程序无法正常工作。请注意,我以前从未使用过.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的内容,那么它回声正常。
它只是随机发布到atestimonial div中。
实际的div和按钮的结构是这样的:
<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股利不显示?
感谢您抽出时间来阅读。
快速编辑
这是工作在本地主机上;我刚刚读到,这不适用于本地主机,这是正确的吗?
首先,检查你的.load返回任何数据。其次,检查你的jQuery - 在你加载函数时,你不会对返回的数据做任何事情(如果有什么返回的话)。 – Marcus
您试图将内容加载到'id =“atestimonial”''div',这不存在于您的页面上。 –
你的jQuery在你的html中选择'#atestimonial'而你的div有一类'.atestimonial',而不是id。 – Mudshark