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 #testimonial は 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 とボタンの構造は次のとおりです。

<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 では機能しないと読みましたが、これは正しいですか?

4

1 に答える 1

2

jQuery に fill を要求しています。これ$('#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 に答える