1 回答

TA貢獻2041條經驗 獲得超4個贊
創(chuàng)建/更新時維護一個輸入字段,如下所示value=''
當然,value=""在“創(chuàng)建”時和“更新”操作時的某些值(正在更新的記錄的 ID),您必須根據正在執(zhí)行的操作進行設置。
<input type="hidden" name="update_id" value='' id="update_id">
現在在驗證的時候
username: {
required: true,
remote : {
type: "POST",
async: false,
url: yourUrlHere,
data: {
id: function()
{
return $("#update_id").val();
}
}
}
}
在這里我們發(fā)送 update_id,無論操作是創(chuàng)建/更新即“”,同時創(chuàng)建和更新時的一些值(正在更新的記錄的 id)。
然后,您可以在頁面上使用用戶名檢查邏輯,url: yourUrlHere,例如 'id'= '' then check from all records for duplicate username or if 'id'= 'someVal' then check from all records for duplicate username except 'id'= 'someVal'
- 1 回答
- 0 關注
- 96 瀏覽
添加回答
舉報