2

I am trying to develop a simple login page , using PHP , AJAX and MySql. And after a long struggle , I did this :

    <head>
  <link rel="stylesheet" type="text/css" href="css\\login.css">
  <script  src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">

                    function do_login()
                    {
                     var username=$("#username").val();
                     var pass=$("#password").val();
                     if(email!="" && pass!="")
                     {

                      $.ajax
                      ({
                      type:'post',
                      url:'serveur.php',
                      data:{
                       do_login:"do_login",
                       username:username,
                       password:pass
                      },
                      success:function(response) {
                      if(response=="success")
                      {
                        window.location.href="index.php";
                        console.log(1);
                      }
                      else
                      {

                        alert("Wrong Details");
                        console.log(0);
                      }
                      }
                      });
                     }

                     else
                     {
                      alert("Please Fill All The Details");
                     }
                        return false ; 


                    }

</script>
</head>

</style>
<body>


<div class="login-page">
  <div class="form">

    <form class="login-form">
      <input type="username" placeholder="username" id="text" />
      <input type="password" placeholder="password" id="password" />
      <button type="submit" id="loginButt" onclick="do_login()">login</button>
      <p class="message"><a href="1stPage.html">Go Back</a></p>
      <div id="resultat ">Authentification result Here ....</div>
    </form>
  </div>
</div>
</body>

But I have this error message :

Uncaught ReferenceError: do_login is not defined at HTMLButtonElement.onclick

Ashish Bahl
  • 1,482
  • 1
  • 18
  • 27
Mehdi Bajjou
  • 59
  • 1
  • 6

1 Answers1

1

Your <script> tag has both a body and a src attribute.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
    // This is the body of the script tag
    function do_login() {
        //...
    }
</script>

The src attribute of the <script> tag has precedence over the body of the tag (see JavaScript: Inline Script with SRC Attribute?). So this means your do_login function is never actually being defined :(

Try changing it to

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" />
<script type="text/javascript">
    function do_login() {
        //...
    }
</script>
Community
  • 1
  • 1
jacobianism
  • 226
  • 1
  • 3
  • 12