我有以下代码片段。我已将注释放在未执行的代码之前。
$(document).on('click', '#disable_url', function (e) {
e.preventDefault();
var items = new Array();
$("input:checked:not(#ckbCheckAll)").each(function() {
items.push($(this).val());
});
var str = $("#user_filter").serialize();
var str = decodeURIComponent(str);
var user_status = new Array();
for (var i = 0; i < items.length; i++) {
//user_status.push($("#"+items[i]).val());
user_status.push($("#"+items[i]).val().replace(/'/g,''));
}
$.ajax({
type: "POST",
url: "manage_users.php?op=disable_bulk_users&items="+items+"&options="+str+"&user_status="+user_status,
dataType: 'json',
success: function(data) {
var redirect_link = data.href;
window.location.href = redirect_link;
}
});
/*The below code is not getting executed. It is expected to be executed upon the success response from PHP file otherwise not*/
for (var i = 0; i < items.length; i++) { alert("Nibble");
var status = 'enable';
id = items[i];
$('#user_status_'+id).html('<img src="{/literal}{$control_img_url}{literal}disable.png" border="0" alt="Enable User" width="20" height="20" />');
$('#user_status_'+id).attr('title','Enable User');
$('#user_status_'+id).attr('onClick', "change_user_status('"+module_url+"', '"+op+"', '"+id+"', '"+status+"');return false;");
}
/*The non calling code ends here*/
})
从请求到成功响应和页面重定向的一切工作正常,但我无法在收到来自 PHP 文件的成功响应后执行代码。如果未收到成功响应,则不应执行此代码。你能在这方面帮助我吗?提前致谢。