Joined: Tue Mar 27, 2007 10:55 pm Posts: 1573 Location: Earth Has thanked: 10 time Have thanks: 16 time
Hi, i have created a code to login using ajax , the code is so easy , here i have two files , one contain the ajax code with a form to login and other file contain the check on the username and password . Here is the first file Ajaxlogin.php :
Code:
<html> <head> <script language="javascript"> function postRequest(strURL){ var xmlHttp; if(window.XMLHttpRequest){ // For Mozilla, Safari, ... var xmlHttp = new XMLHttpRequest(); } else if(window.ActiveXObject){ // For Internet Explorer var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttp.open('POST', strURL, true); xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttp.onreadystatechange = function(){ if (xmlHttp.readyState == 4){ ajaxloginupdate(xmlHttp.responseText); } } xmlHttp.send(strURL); }
function ajaxloginupdate(str){ if(str=="ok"){ alert("Hi , user"); }else{ alert("Login falied try again later"); } }
function loginajax(){ var username = window.document.loginform.username.value; var password = window.document.loginform.password.value; var url = "login.php?username=" + username + "&password=" +password ; postRequest(url); } </script> </head>
Here the second file , you can make a check for the username and password in your database ,but for simplicity i just make a check for a certain username and password .
Users browsing this forum: No registered users and 1 guest
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum