I have a HTML file which have Last Name and Code to access a website. I want to do a JavaScript validation on my html Form to validate credential.
action="https://www.somewebsite.com/doctor_autho.php?action=login&type=login"
The form action in HTML file send this kind of data
{"result":"true","msg":"redirect to home.html"}
{"result":"false","msg":"The Invitaion code or Last Name is wrong used!"}
{"result":"false","msg":"Parameter wrong used!"}
Please suggest how to do validation as my page is html. And want to do it using Javascript or JQuery as I have limited knowledge on PHP.
Can something like this work ?
<script type='text/javascript'>
$(document).ready(function(){
$('#accessform').on('submit', function(event){
event.preventDefault();
$.ajax({
url:"https://www/doctor_autho.php?action=login&type=login",
method:"POST",
data:$(this).serialize(),
dataType:"json",
beforeSend:function(){
$('#submit').attr('disabled', 'disabled');
},
success:function(data)
{
if(data.result)
{
if(data.result = 'false')
{
$('#login_error').html("<strong> Valid credential required </strong>");
}
else
{
$('#name_error').html('');
}
}
$('#submit').attr('disabled', false);
}
})
});
});
</script>