It's a weird issue. I've to click on certain buttons (having some ids). The id is passed through Ajax in a PHP script. That id is searched in the database, and the matching entries are passed as data in which is shown in my jQuery lightbox. However, I have to double-click on the button for the first time.
My HTML structure is as follows:
<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>
And the Javascript function is:
$('.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>'
});
});
});
My relevant PHP script:
$id = $_POST['id'];
$result = mysql_query("SELECT * FROM `eventdetails` WHERE `id` = '".$id."'");
$array = mysql_fetch_row($result);
echo json_encode($array);
I'm running the files on an XAMPP server on Windows 7. Is it normal that I've to double click for the first time? How can I improve it?
EDIT #1
One of the users suggested of using success
instead of done
in Ajax. Still, it requires a double-click. Here's the javascript code using success
in Ajax.
$('.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>'
});
})
});
});