jac*_*ack 2 ajax jquery array-push
我正在尝试将一个div id推入一个数组.Array push正在运行良好的bofore 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]
Run Code Online (Sandbox Code Playgroud)
我的代码
$(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");
}
}
})
}
});
});
Run Code Online (Sandbox Code Playgroud)
我错了..或者这就是它的工作方式?提前致谢
| 归档时间: |
|
| 查看次数: |
1970 次 |
| 最近记录: |