У меня есть кнопка, которая передает данные через ajax. Затем, когда у меня есть это изменение на другую кнопку, которая затем создает цикл между двумя кнопками.JQuery, кнопка ajax не работает
Однако вторая кнопка не может быть нажата. Любая идея почему? Heres мой код:
<div class="<?PHP echo $value['id'];?>"><button class="checkin" id="<?PHP echo $value['id'];?>">Checkin</button></div>
<script type="text/javascript">
$(function() { // wrap inside the jquery ready() function
//Attach an onclick handler to each of your buttons that are meant to "approve"
$(".checkin").click(function(){
//Get the ID of the button that was clicked on
var id_of_item_to_approve = $(this).attr("id");
$.ajax({
url: "checkin_user.php", //This is the page where you will handle your SQL insert
type: "POST",
data: "eventid=<?PHP echo $eventId;?>" + "&id=" + id_of_item_to_approve, //The data your sending to some-page.php
success: function(){
alert("AJAX request was successfull");
$("." + id_of_item_to_approve).html('<button class="checkout" id="' + id_of_item_to_approve + '">Check Out</button>');
},
error:function(){
alert("AJAX request was a failure");
}
});
});
//Attach an onclick handler to each of your buttons that are meant to "approve"
$(".checkout").click(function(){
//Get the ID of the button that was clicked on
var id_of_item_to_approve = $(this).attr("id");
$.ajax({
url: "checkin_user.php", //This is the page where you will handle your SQL insert
type: "POST",
data: "checkout=1&eventid=<?PHP echo $eventId;?>" + "&id=" + id_of_item_to_approve, //The data your sending to some-page.php
success: function(){
alert("AJAX request was successfull");
$("." + id_of_item_to_approve).html('<button class="checkin" id="'+ id_of_item_to_approve +'">Check In</button>');
},
error:function(){
alert("AJAX request was a failure");
}
});
});
});
</script>
Поиск делегированных обработчиков событий. Или посмотрите на http://api.jquery.com/on – ahren