dongmaopiao0901 2015-12-27 05:38
浏览 63

使用AngularJS和AJAX验证数据库的电子邮件地址

I have an <input> tag in my form:

<input type="email" name="Email_i" placeholder="enter email here" id="e_mail" onBlur="loadDoc(this.value)">

After the input loses focus, the following function is called that uses AJAX:

<script>
function loadDoc() {
    var no = document.getElementById("e_mail").value;

    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("check").innerHTML = xhttp.responseText;
        }
    };

    xhttp.open("GET", "ajax.php?email="+no, true);
    xhttp.send();
}
</script>

And here is the PHP logic from ajax.php:

<?php
session_start();

$email = $_GET['email'];

include "config.php";

$check = mysql_query("select * from registration_form where EMail ='$email' and EMail <> ''",$con);
if (mysql_num_rows($check) == 1)
{
    echo '<p style="color:#ff0000">Email Already Exists</p>';
    $_SESSION['email'] = "yes";
}
else
{
    echo '<p style="color: #00ff00">available</p>';
}

I want to do this operation using AngularJS, that verifies the email address from the database, but it's not working. Can you help me?

  • 写回答

1条回答 默认 最新

  • dt250827 2015-12-27 05:56
    关注

    Why not just use jQuery alongside Angular? The code would be much simpler. Also, please do not use the deprecated mysql. Use mysqli. The code should be essentially the same with just an 'i' added to your mysql query.

     $.get("ajax.php", {email: $("#e_mail").val()}, function(){
        alert("Success!");
    });
    

    Sorry, made some careless errors at first. I edited everything. I hope it works for you.

    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等