如何使用PHPAPI通过Javascript进行验证

如何使用PHPAPI通过Javascript进行验证,javascript,Javascript,我有一个HTML文件,其中有姓氏和访问网站的代码。我想在我的html表单上进行JavaScript验证,以验证凭证 action="https://www.somewebsite.com/doctor_autho.php?action=login&type=login" HTML文件中的表单操作发送此类数据 {"result":"true","msg":"redirect to home.html"} {"result":"false","msg":"The Invitaion cod

我有一个HTML文件,其中有姓氏和访问网站的代码。我想在我的html表单上进行JavaScript验证,以验证凭证

action="https://www.somewebsite.com/doctor_autho.php?action=login&type=login"
HTML文件中的表单操作发送此类数据

{"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!"}
请建议如何做验证,因为我的网页是html。我想使用Javascript或JQuery来实现它,因为我对PHP的知识有限

像这样的东西行吗

 <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>

$(文档).ready(函数(){
$('#accessform')。在('submit',函数(事件){
event.preventDefault();
$.ajax({
url:“https://www/doctor_autho.php?action=login&type=login",
方法:“张贴”,
数据:$(this).serialize(),
数据类型:“json”,
beforeSend:function(){
$('提交').attr('禁用','禁用');
},
成功:功能(数据)
{
if(data.result)
{
如果(data.result='false')
{
$(“#登录错误”).html(“需要有效凭证””;
}
其他的
{
$('#name_error').html('');
}
}  
$(“#提交”).attr('disabled',false);
}
})
});
});

您可以使用event.prevent默认提交事件,检查此答案客户端验证是否容易被欺骗(黑客攻击)。有限的PHP知识不足以让我们放弃学习如何使用
$\u POST
$\u GET
。我建议您学习客户端和服务器端验证。话虽如此,您可以发布源代码,而不仅仅是您期望的数据吗?正如GetSet所提到的,客户端(javascript)验证等同于根本没有验证。它应该只用于UX原因,而不是安全性。实际上,如果这些凭据有效,我想重定向到一个新页面。