I work on asp.net mvc Application Ajax Request Calling I face Issue message sweet alert display more than once if i click button submit more than once
if i press same button submit again for same request it will display (message Employee Exist Before) two time
if i press same button submit button again for same request it will display message validation (message Employee Exist Before) 3 time
correct or expected behavior
when click submit button and employee exist before then show message validation (message Employee Exist Before) one time only .
why that happen and how to prevent display same message multi time
<form id="ResignationApp" style="padding-top: 50px; border: 2px solid black;padding-left:20px;margin-top:30px;"> <input id="btnsubmit" type="submit" style="background-color: #05014a; color: #fff; height: 30px; width: 150px" /> </form> $("#ResignationApp").submit(function (e) { e.preventDefault(); var formData = $(this).serialize(); console.log("data is" + formData) $.ajax({ type: "POST", dataType: 'json', url: '@Url.Action("RequesterIndex", "Resignation")', data: formData, success: function (response) { for (let item of response) { if (item.Key === "success") { success = item.Value; } if (item.Key === "message") { message = item.Value; } } if (success) { Swal.fire({ icon: 'success', title: 'Submition Request', text: message }).then((result) => { if (result.isConfirmed) { var url = '@Url.Action("IndexResignation", "Home")' + '?filenumber=' + empidval; window.open(url, '_self'); } }); } else { Swal.fire({ icon: 'error', title: 'Resignation Submission Form', text: 'Employee Exist Before' }); return false; } }, error: function (error) { var url = '@Url.Action("UnauthorizedUser", "Home")' + '?filenumber=' + empidval; window.open(url, '_self'); } }); }); public JsonResult RequesterIndex(ResignationRequester resignationRequester) { dynamic responseData = new ExpandoObject(); responseData.success = false; responseData.message = ""; var filenumber = resignationRequester.EmpID; if (Session[SessionKeys.UserCode] != null) { JDEUtility jde = new JDEUtility(); if (ModelState.IsValid) { int checkEmployeeNoExist = jde.CheckEmployeeExistOrNot(resignationRequester.EmpID); if (checkEmployeeNoExist >= 1) { responseData.success = false; responseData.message = "Employee Exist Before"; return Json(responseData); } try { Workforce.InsertToReignation(resignationRequester, JoinedDate, (string)Session[SessionKeys.Username], (DateTime)Session[SessionKeys.LastWorkingDate], noticeperiod, (int)Session[SessionKeys.UserCode]); } catch (Exception ex) { responseData.success = false; responseData.message = "Create Not Done Correctly"; return Json(responseData); } if (string.IsNullOrEmpty(ViewBag.errorMsg)) { responseData.success = true; responseData.message = "Resignation Submission form Created successfully"; return Json(responseData); } } else { responseData.success = false; var errors = ModelState.Select(x => x.Value.Errors) .Where(y => y.Count > 0) .ToList(); responseData.message = "Some Required Fields Not Added"; return Json(responseData); } } else { responseData.success = false; responseData.message = "No Data For This File No"; return Json(responseData); } return Json(responseData); }