0

それは奇妙な問題です。特定のボタン (いくつかの ID を持つ) をクリックする必要があります。ID は、PHP スクリプトで Ajax を介して渡されます。その ID がデータベースで検索され、一致するエントリがデータとして渡され、jQuery ライトボックスに表示されます。ただし、初めてボタンをダブルクリックする必要があります。

私のHTML構造は次のとおりです。

<div class="boxes">
  <a href="#" id="showe3" class="button lfloat">Show it</a>
</div>
<div class="boxes">
  <a href="#" id="showe4" class="button lfloat">Show it</a>
</div>

Javascript関数は次のとおりです。

$('.button').click( function() {
  $.ajax({
    type: 'POST',                
    url: 'functions/db.php',            
    data: {id: this.id},
    dataType: 'json'
  }).done(function(data) {
    $('#'+data[0]).avgrund({
    //data [0] is both the id being clicked and that stored in the database
      height: 200,
      holderClass: 'custom',
      showClose: true,
      template: '<p>'+data[2]+'</p>' +
        '<div>' +
        '<a href="#" target="_blank" class="b1">'+data[0]+'</a>' +
        '<a href="#" target="_blank" class="b2">'+data[1]+'</a>' +
        '<a href="#" target="_blank" class="b2">More</a>' +
        '</div>'
    });
  });

});

関連する PHP スクリプト:

$id = $_POST['id'];
$result = mysql_query("SELECT * FROM `eventdetails` WHERE `id` = '".$id."'");                      
$array = mysql_fetch_row($result);                            
echo json_encode($array);

Windows 7 の XAMPP サーバーでファイルを実行しています。初めてダブルクリックする必要があるのは正常ですか? どうすれば改善できますか?

EDIT #1ユーザーの 1 人が、Ajaxsuccessの代わりに 使用することを提案しました。doneそれでも、ダブルクリックが必要です。successAjax で使用する JavaScript コードを次に示します。

$('.button').click( function() {
  $.ajax({
    type: 'POST',                
    url: 'functions/db.php',            
    data: {id: this.id},
    dataType: 'json',
    success:(function(data) {
      $('#'+data[0]).avgrund({
        height: 200,
        holderClass: 'custom',
        showClose: true,
        template: '<p>'+data[2]+'</p>' +
          '<div>' +
          '<a href="#" target="_blank" class="b1">'+data[0]+'</a>' +
          '<a href="#" target="_blank" class="b2">'+data[1]+'</a>' +
          '<a href="#" target="_blank" class="b2">More</a>' +
          '</div>'
      });
    })
  });
});
4

1 に答える 1

3

ajax データで avgrund を初期化するには、「openOnEvent」という特別なパラメータを「false」に設定します。次のようになります。

$.ajax({
            type: 'POST',
            url: 'testpost.php',
            dataType: 'json',
            data: { id: this.id },
            success: function(id) {
                $('#' + id).avgrund({
                    openOnEvent: false,
                    height: 200,
                    template: '<p>content <b>' + id + '</b> here!</p>'
                });
            }
        });

ドキュメント - https://github.com/voronianski/jquery.avgrund.js#update-sep-30-2012 テスト ページ - http://labs.voronianski.com/test/test-avgrund.html

于 2013-01-10T10:49:10.527 に答える