-3
我有以下代碼片段。我在未執行的代碼之前放置註釋。從申請到成功響應和頁面重定向
$(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文件成功響應執行代碼。如果未收到成功響應,則不應執行此代碼。在這方面你能幫助我嗎?提前致謝。
如果一旦請求成功返回,您是否重定向用戶?您是否期望代碼被執行? – Lix
@Lix:其實如果你注意到我正在改變一些HTML代碼。 HTML的這種改變預計會在成功響應時完成,並且頁面也需要重定向。 – PHPLover
那麼爲什麼不直接在請求之前執行代碼呢?甚至在重定向之前的成功回調裏面... – Lix