Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Ajax php login query via onlick

$
0
0
Hello,

I am building a webpage and i found that most of my functions requires the whole webpage to reload. for example login the page will reload and display success or error. I found out that ajax can be used. the problem is that i don't know how.sI made this code and it does not work. I did it by onchange but not using onlick. this is my code fragment
<title>Untitled Document</title>
</head>
	<script>
        function call_login(username, password)
        {
           
        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
          }
        else
          {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        xmlhttp.onreadystatechange=function()
          {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
            }
          }
        xmlhttp.open("GET","user_login.php?u="+username+"&p="+password,true);
        xmlhttp.send();
        }
        
        
            var klient;
            function ajax(filurl) {
                 klient = new XMLHttpRequest();
                 klient.onreadystatechange = hanterare;
                 klient.open("GET", filurl);
                 klient.send(null);
                }
            function hanterare() {
                document.getElementById("utdata").innerHTML= klient.responseText;
            }
            
        </script>

<body>
<form>
    <p>USERNAME: 
    <input type="text" name="usermame" id="username">
    </p>
    <p>PASSWORD:
      <label for="password"></label>
      <input type="password" name="password" id="password">
    </p>
    <p>
      <input type="submit" name="call_login" id="call_login" value="Submit" onclick="call_login(document.getElementById('username'), document.getElementById('password')">
    </p>
</form>
<label for="call_login"></label>
</body>
</html>

Hope somebody helps. Thanks!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>