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.

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向