我已经阅读了.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的内容,那么它就会正确回声。
这只是随机发布到了atstimonial 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显示在div中?
感谢您花时间阅读本文。
快速编辑
这适用于localhost;我刚刚读到这对localhost不起作用,这是正确的吗?
答案 0 :(得分: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() {