在我的Web應用程序(使用Zend Framework)向數據庫添加新實體時,應檢查此實體是否已被添加和刪除。 (從數據庫刪除實體時,該特定記錄的「狀態」列更新爲0(零)。)在用戶確認時使用jquery重定向到新頁面
如果實體先前已刪除,系統要求確認以編輯以前刪除的記錄,或添加一個新的紀錄。如果用戶需要編輯以前添加的記錄,則應將用戶重定向到編輯頁面。
這個檢查和重定向是使用jQuery完成的。這裏是我正在使用的jQuery代碼:
$("input[name=btnSubmit]").click(function(){
var name = $("input[name=txtTblPrefix]").val();
var parameters = 'name='+name;
$.ajax({
url: '../admin_mapping/get-id',
async:false,
data:parameters,
type:'POST',
dataType: 'text',
success: function(data)
{
var res = confirm("There is a record already added to the database for "+name+". Do you want to edit it?");
if(res)
{
window.location.replace("../admin_mapping/edit?id="+data);
}
}
});
});
在這段代碼中,除了重定向之外,所有的工作都完美無缺。我已經單獨測試了線路window.location.replace("../admin_mapping/edit?id="+data);
,它工作正常。即使confirm()
函數返回true
。
我曾嘗試在if
條件內放置alert()
,並提示警報。但重定向不起作用。
任何人都可以幫助我嗎?
在此先感謝
「../admin_mapping/edit?id="+data – gurvinder372
它的值是什麼?它返回一個整數。該值正在返回。我也檢查過 –
使用'window.location.href =「../admin_mapping/edit?id=」+ encodeURIComponent(data)'而不是? – Alexander