Register page with webapi and jquery

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <ul></ul>
    <input type="text" id="txtemail" /><br />
    <p id="errormsg"></p><br />
    <input type="text" id="txtpwd" /><br />
    <input type="button" id="alert" value="Register" />


    <script src="jquery-3.3.1.min.js"></script>
    <script>
        var http = "http://localhost:50237/api/constitution";

        var error = $("#errormsg").val();
        var list = $("ul");
        var useremails = [];
        var v;

        $(document).ready(function () {
            $.ajax({
                url: http,
                method: 'GET',
                dataType: 'json',
                success: function (data) {
                    $.each(data, function (idx, elem) {
                        useremails.push(elem.U_EMAIL)
                    });
                }
            });
        });

        $("#alert").click(function () {
            var email = $("#txtemail").val();
            var pwd = $("#txtpwd").val();
            var error = $("#errormsg").val();
            var v = 0;
            for (var i = 0; i <= useremails.length; i++) {
                if (useremails[i] == email) {
                    v++;
                    if (v == 1) {
                        $("p").text("Already Registered");
                    }
                }
                if (v == 0) {
                    $.ajax({
                        type: "POST",
                        url: http + "?" + "email=" + email + "&" + "pwd=" + pwd,
                        contentType: "application/json",
                        async: false,
                        success: function () {
                            $("p").text("Registered successfully");
                        }
                    });
                   
                }
            }
        });
    </script>
</body>
</html>

Comments

  1. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info.
    Online Education App in India

    ReplyDelete

Post a Comment

Popular posts from this blog

Automatically send Birthday email using C#.Net

Drag and Drop multiple File upload using jQuery AJAX in ASP.Net using C# and VB.Net

Difference between each and map in jquery