【发布时间】:2016-04-23 20:39:32
【问题描述】:
<button class='btn btn-success activeAccount'>Activate Account</button>
我在onclick事件上触发ajax调用,下面是ajax调用代码:
$(".activeAccount").click(function() {
var intCounselorId = $(this).parent().parent().find('input[class="counselorId"]').attr("value");
var intOwnerId = $(this).parent().parent().find('input[class="userID"]').attr("value");
var strAction = 'activateAccount';
performAction(intCounselorId, intOwnerId, strAction);
});
function performAction(intCounselorId, intOwnerId, strAction) {
$.ajax({
url: '/admin/counselormanagement/expertmanagementgridaction',
data: 'intCounselorId='+intCounselorId+'&intOwnerId='+intOwnerId+'&strAction='+strAction,
type: "POST",
async:false,
success: function(intFlag) {
if(intFlag == 1){
location.reload();
}
}
});
}
我正在尝试运行一个在第一页上正常工作的 onclick 事件,但一旦我进入第 2 页(或任何其他页面),它就会停止工作。
我正在使用 jquery-1.10.2.min.js 和 1.9.4 版本的数据表
【问题讨论】:
-
.activeAccount按钮是否在表格内容中?另外,请注意使用async: false是非常糟糕的做法,并且成功处理程序中的location.reload()完全否定了首先发出AJAX 请求的全部意义。 -
是的,在表格内容下
-
在这种情况下,您需要根据@squaleLis 的回答使用委托事件处理程序。不过,您真的应该摆脱
async: false和location.reload()。 -
我已经在这里给出了答案。 stackoverflow.com/questions/25575996/…你可能会看到这个。
-
@Md.HarunOrRashid 提出的解决方案真的很有帮助
标签: javascript jquery ajax datatable