Jump to content

Javascript error?


phpSensei

Recommended Posts

Hello everyone, I am still on the quest of exploring this wonderful language, javascript and ajax. Although i came by some problems which doesn't occur IE7 or 6, but only FireFox...

 

Don't know if its something with ajax or javascript...

 

sendObj has no properties on line 49

 

Line 47,48,49..etc

 

			
48:			} 
49:  
50:     }  else{
51:	   
52:	        sendObj.open('get','validateLogin.php?username='+username+'&password='+password);
	  sendObj.onreadystatechange = handleLogin;
	  sendObj.send(null);
       }
}

 

 

Script

<script language="JavaScript" type="text/javascript">
function createObject(){

var Req;
  if(window.XMlHttpRequest){
  
   Req = new XMLHttpRequest();
     }else if(window.ActiveXObject){

  Req = new ActiveXObject("Microsoft.XMLHTTP");
  
  }
  return Req;
  }

  var getObj = createObject();
  var sendObj = createObject();
  
function userLogin(){

  var username = document.getElementById('user').value;
  var password = document.getElementById('pass').value;
  
   if(username == '' || password == ''){
   
    alert('Please enter your username and password');

 if(username == ''){ 

   document.getElementById('user').focus(); 
     
	  }else{
	  
	    document.getElementById('pass').focus();} 
   
     }  else{
   
      sendObj.open('get','validateLogin.php?username='+username+'&password='+password);
	  sendObj.onreadystatechange = handleLogin;
	  sendObj.send(null);
       }
}

function handleLogin(){

if(sendObj.readyState == 1){ document.getElementById('stats').innerHTML = '<img src="../../ims/loader.gif">'; document.getElementById('loginBTN').innerHTML = 'Processing Login...'; }
else if(sendObj.readyState == 4 && sendObj.status == 200){

    // 1 wrong username
// 2 empty
// 3 logged in
 document.getElementById('stats').innerHTML = '<span class="red">Try Again </span>'; document.getElementById('loginBTN').innerHTML = '<a href="javascript:userLogin();">Log In</a>';
  var response = sendObj.responseText;
  
   if(response == '1'){
          
	  alert('Wrong Username or Password');
      
    }else if(response == '2'){

	  alert('Empty Field Detected, possible hack attempt');

	}else{

	  window.location = '../../index.php';

	}
 }
}
</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.