我正在尝试将 div id 推送到数组中。数组推送在 ajax 调用之前运行良好。但是当我在 ajax 中使用 push 成功时,当我单击第二个元素时会发生第一次推送。那就是
使用以下代码时的数组操作(数组推入成功)
first click on id="1" --- resuting array []
second click on id="2" --- resulting array [1]
second click on id="3" --- resulting array [1,2]
我的代码
$(document).ready(function() {
var count = 0;
var vPool = '';
arr = [];
seat = [];
var totalseat = '<?php echo $sumofseat; ?>';
var date = ' <?php echo $new_date; ?>';
$('.custom_checkbox').click(function() {
pressed = true;
var prev = $(this).attr('class');
var arrid = $(this).attr('id');
var seats = $(this).attr('title');
count = $('.selected').length;
if (prev == 'custom_checkbox') {
//arr.push(arrid);
//seat.push(seats);
$.ajax({
url: "seat_manipulation.php",
dataType: 'json',
data: '&operation=save&seat=' + arrid + '&guid=<?php echo $guid; ?>&date=' + date,
type: "POST",
context: this,
success: function(data) {
if (data.status == 'SAVED') {
$(this).toggleClass('selected');
$('#count').slideDown();
$('#selecte_seat').show();
$('#count').html(count + ' Seats selected');
alert(arrid);
//if(jQuery.inArray(arrid,arr) == -1) {
arr.push(arrid);
//}
//if(jQuery.inArray(seats,seat) == -1) {
seat.push(seats);
//}
} else {
alert("Seat already been used.Please select another");
}
}
})
}
});
});
我错了..或者这就是它应该如何工作?提前致谢