Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // about on line 37, there is a ajaxRequest.responseText that has no value
- var store_reguser;
- var ajaxRequest;
- /* in ajax() I am trying to assign a value to ajaxRequest
- to make it possible to do ajax requests */
- function ajax()
- {
- if (window.XMLHttpRequest)
- {//Code for IE7+, Firefox, Chrome, Opera, Safari
- ajaxRequest=new XMLHttpRequest();
- console.log('making ajaxRequest worked');
- }
- else
- {//code for IE6, IE5
- ajaxRequest=new ActiveXObject("Microsoft.XMLHTTP");
- }
- }
- /* What this function does is that it checks if the username and password correspond.
- It is a simple login function.*/
- if(ajaxRequeast=aslkdj){}
- function loginFunction()
- {
- console.log('thefuncisexecuted');
- ajaxRequest.onreadystatechange = function(){
- if(ajaxRequest.readyState == 4)
- {
- if(ajaxRequest.responseText == "ok")
- {
- console.log('passwords match');
- logintosite();
- }
- else
- {
- //***The error is here //Here
- console.log ('expecting not ok ' +ajaxRequest);
- document.getElementById('mySpan2').innerHTML = ajaxRequest.responseText;
- }
- }
- }
- //sending the username and password to the sever
- var usernameID = document.getElementById('usernameID').value;
- var password = document.getElementById('password').value;
- var queryString2 = "?username=" +usernameID +"&pass=" +password;
- ajaxRequest.open("GET", "checkLogin.php" +queryString2, true);
- ajaxRequest.send(null);
- console.log('you reached it');
- }
- /* Here, I am trying to see if the input is okay. I use in_ and out because there are two
- different inputs ( register and login ) which use this function. I did this just because
- of a recommendation on an IRC chat.
- What the function does is that it sends the input
- to ServerUsers to check if this username exists in the database.*/
- function usernameVer(in_, out)
- {
- //function which will get data from server.
- ajaxRequest.onreadystatechange = function()
- {
- if(ajaxRequest.readyState == 4)
- {
- var input = document.getElementById(in_).value;
- if(input != "")
- {
- console.log('yeah: ' +ajaxRequest);
- if(in_ == 'user1') // <-- If the input is the registration input
- {
- if(ajaxRequest.responseText == "cross")
- // ^-- If the server response is a redcross, it means that the username does not exist in the database
- {
- console.log('response:' +ajaxRequest.responseText);
- document.getElementById(out).innerHTML = "<img src='greencheck.png' height='20' width='20' />"
- // ^-- So it is okay for the user to use that username for registration
- //Ignore this, it is related to disabling/enabling the registration button
- store_reguser = "nodisable";
- if(store_regpass == "ok")
- {
- document.getElementById('regbutton').disabled = false;
- }
- }
- if(ajaxRequest.responseText == "check")
- // Same as above, but inverted. So if the username exists on the db, the person cannot register with that username...
- {
- console.log('expecting a username' +document.getElementById('user1').value);
- document.getElementById(out).innerHTML = "<img src='redcross.png' height='20' width='20' />";
- //Ignore this --v
- store_reguser = "disable";
- document.getElementById('regbutton').disabled = true;
- }
- }else{
- if(ajaxRequest.responseText == "check"){
- document.getElementById(out).innerHTML = "<img src='greencheck.png' height='20' width='20' />";
- }else{
- document.getElementById(out).innerHTML = "<img src='redcross.png' height='20' width='20' />";
- }
- }
- }
- else
- {// If the input is empty, it disables the registration button...
- document.getElementById('regbutton').disabled = true;
- document.getElementById(out).innerHTML = "";
- }
- }
- }
- // Here, it sends the username to the server
- var usernameID = document.getElementById(in_).value;
- var queryString = "?usernameID=" +usernameID;
- ajaxRequest.open("GET", "ServerUsers.php" +queryString, true);
- ajaxRequest.send(null);
- }
- /* Here I check if the first password in the registration form is equal to the second one,
- If they are not the same, there is a redcross appearing next to the input and the
- registration button is disabled*/
- var store_regpass;
- function confirmPass(){
- var pass1 = document.getElementById('pass1').value;
- var pass2 = document.getElementById('pass2').value;
- if(pass1 == pass2) // Pretty simple
- {
- var greencheck = "<img src='greencheck.png' height='20' width='20' />";
- document.getElementById('confpass').innerHTML = greencheck;
- document.getElementById('regbutton').disabled = false;
- //Ignore this --v Trying to make the registration more user friendly
- store_regpass = "ok";
- console.log ('expecting a username ' +document.getElementById('user1').value);
- if (store_reguser == "disable" || !store_reguser || store_reguser == "" || document.getElementById('user1').value == ""){
- console.log ('store_reguser');
- document.getElementById('regbutton').disabled = true;
- }
- }
- else
- {
- //Ignore this
- store_regpass = "not ok";
- var redcross = "<img src='redcross.png' height='20' width='20' />";
- //If the passwords do not match, there is a red cross...
- document.getElementById('confpass').innerHTML = redcross;
- document.getElementById('regbutton').disabled = true;
- }
- }
- /* This function simply checks if the inputs in the login for are filled or not,
- If they are filled, the user can try to log in. If they are not, the login
- button is disabled. */
- function checkIfLog(){
- var user = document.getElementById('usernameID').value;
- var pass = document.getElementById('password').value;
- if(pass == "" || user == "")
- {
- document.getElementById('submitLog').disabled = true;
- }
- else
- {
- document.getElementById('submitLog').disabled = false;
- }
- }
- /* This function is used to register a username and a password to a database. */
- function registerR(){
- ajaxRequest.onreadystatechange = function(){
- if(ajaxRequest.readyState == 4){
- if(ajaxRequest.responseText == "ok"){ //If the server return "ok", then the registration WORKED.
- document.getElementById('regspan').innerHTML = "Registration was a success! You can now Log in.";
- }
- else{ //If it returns "not ok", the registration FAILED
- document.getElementById('regspan').innerHTML = "Registration Failed.";
- console.log('expecting a response other than "ok": ' +ajaxRequest.responseText);
- }
- }
- }
- //Sends the values username, password1, and password2 to the server.
- var username = document.getElementById('user1').value;
- var password1 = document.getElementById('pass1').value;
- var password2 = document.getElementById('pass2').value;
- var query = "?usernameR=" +username +"&passwordR1=" +password1 +"&passwordR2=" +password2;
- ajaxRequest.open("GET", "register.php" +query, true);
- ajaxRequest.send(null);
- //console.log ('expecting a query' +"register.php" +query);
- }
- function logintosite(){
- window.location = "loggedIn.php";
- }
Add Comment
Please, Sign In to add comment