I have a two input boxes with name and email. Those names and emails are already stored in the database. One unique URL will be genereated for each user and email will be sent to the user along with URL. Once the user clicks the unique url it goes to new page and there they have enter the already registered name and email.If the name or email ,either of them is not correct we have an alert box mentionioning that "there is some error,enter the proper email or name". This is my expected output Now if I click the 'ok' in the alert box it should stay in the same page. But actual output is It's going to some valid page and it's displaying an json response in the page
<form action="/{{ department_id }}/{{url}}/{{student_id}}/valid" method="POST">
<div class="form-group">
<label class="col-md-3 control-label">Enter your name</label>
<div class="col-md-3">
<input id="student-name" name="student-name" type="text" class="form-control input-md"
required>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Enter your email</label>
<div class="col-md-3">
<input id="student-email" name="student-email" type="email"
class="form-control input-md" required>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="save"></label>
<div class="col-md-8">
<input class="btn btn-success show-modal" type='submit' id='submit' value='Go for schedule'>
</div>
</div>
</form>
<script>
$("#submit").click(function ()
{
var student_name = $("#student-name").val();
var student_email = $("#student-email").val();
var departmentId = "{{ result.department_id }}";
var studentId = "{{ result.student_id }}"
var url = "{{ result.url }}"
$.ajax({
type: 'POST',
url: "/" + departmentId + "/" + url + "/" + studentId + "/valid",
data: {
'student-name': student_name,
'student-email': student_email
},
success:function(result)
{
if(result.error=="NameError")
{
alert("Name not found, please enter the same name that you used when applied for this role");
return false;
//history.go(-1);
//document.location.href="/"+result.return_data['student_id']+"/"+result.return_data['department_id']+"/"+result.return_data['url']+"/welcome";
}
if(result.error=="EmailError")
{
alert("Email not found, please enter the same email that you used when applied for this role");
return false;
//history.go(-1);
document.location.href="/"+result.student_id+"/"+result.department_id+"/"+result.url+"/welcome";
}
else{
alert("Something is wrong, try reloading the page or contact admin");
return false;
//history.go(-1);
document.location.href="/"+result.student_id+"/"+result.department_id+"/"+result.url+"/welcome";
}
}
})
})
</script>
I have tried history.go(-1),it's not working. So what is happening is when the user click on the email link it goes /id/id1/url/welcome page. If the entry is wrong it gives an alert and it's going to /id/id1/url/valid page. But I wanted to stay in the same page Any input please