我有一个表中包含一个数组中的每个元素的行。我试图在点击删除图像时删除元素(图像的ID为deleteRowButton
)。此刻,当你点击图片,但是如果我删除var index
线,该表行将淡出预期(但当然数组元素不会删除没有任何反应。从会话数组中删除项Jquery Ajax
$(document).on('click', '#deleteRowButton', function() {
var index = $(this).closest('tr').attr(id);
//Set index to the id of table row (number corresponding to their position in the array)
remove_index(index);
$(this).closest("tr").fadeOut('slow');
return false;
});
function remove_index(value) {
$.post("./remove_array_item.php", {index:value});
}
这里是我的代码remove_array_item.php
删除数组元素:
<?php
include("./config/init.php"); //Contains session_start() etc.
$index = $_POST['index']; //index variable passed in
$ca = $_SESSION["objColl"]; //get array from session variable
$ca->delLineItem($index); //delete item of array at index
$_SESSION["objColl"] = $ca; //store array as session variable
?>
所以我想知道的是:
- 为什么jQuery的功能停止射击,如果我有:
var index = $(this).closest('tr').attr(id);
即,如果我注释掉,该功能将使表行淡出。
- 因为即使当我删除
var index
,只是传递一个值,该指数像这样
remove_index(1);
什么是错我的remove_array_item.php
功能它仍然不会从数组中删除项目,所以当我刷新页面时,该项目回到表格中。