それは奇妙な問題です。特定のボタン (いくつかの 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
それでも、ダブルクリックが必要です。success
Ajax で使用する 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>'
});
})
});
});