Jump to content

the .open function


origaflux

Recommended Posts

Hi.

I've been fighting with this login script for a while now and after fixing other errors, the one that sticks involves actually sending the xml request.

 

Internet Explorer 7: "Object doesn't support this property or method"

Fire Fox 3: "XMLreq.open is not a function."

 

ajax.js - AJAX initiator

function Ajax() {
this.init = function() {
    var i = 0;
    var reqTry = [ 
      function() { return new XMLHttpRequest(); },
      function() { return new ActiveXObject('Msxml2.XMLHTTP') },
      function() { return new ActiveXObject('Microsoft.XMLHTTP' )} ];
      
    while (!this.req && (i < reqTry.length)) {
      try { 
        this.req = reqTry[i++]();
      } 
      catch(e) {}
    }
    return true;
  };
  
    if (!this.init()) {
      alert('Could not create XMLHttpRequest object.');
      return;
    }
}

 

loginform.php - the actual form and handling JS.

<script>
function setOutput(){

if(XMLreq.readyState == 4){
	if(XMLreq.responseText = 'failure') {
		alert("Invalid username or password.");
		alert(XMLreq.responseText.search(/failure/));
	} else {
		document.getElementById("Login").innerHTML = XMLreq.responseText;
		setTimeout('window.location.reload()', 5000);
	}
}
}

function sendL(){
var usn = document.getElementById('username').value;
var psw = document.getElementById('password').value;
document.getElementById("Login").innerHTML = "Processing...";
XMLreq = new Ajax();
if (XMLreq != null) {
	XMLreq.open("GET", "login.php?username="+usn+"&password="+psw, true); //<--code errors refer to here
	XMLreq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	XMLreq.onreadystatechange = setOutput;
	XMLreq.send(null);
} else {
	document.getElementById("Login").innerHTML = "Failed<br />"+
		'<a href="Refresh" onClick="window.reload(); return false;">Refresh?</a>';
}
}
</script>
<body>
<div id="Login">
<form action="javascript:sendL();" method="post" id="loginForm" onSubmit="sendL();">
Username:<input id="username" name="username" type="text" value="" /><br />
Password:<input id="password" name="password" type="password" value="" /><br />
<input type="submit" id="submitButton" name="submitButton" value="Submit" />
</form>
</div>
</body>

 

What am I not doing or doing wrong here?

Thanks in advance.

 

Link to comment
Share on other sites

I kno wnothing about AJAX, you are wondering why I am answering here then, I will try and explain using a small amount of programming knowledge

I have been looking around on the web for information....

 

1.  xxx.open is a function call, that is fact

2.  for your function to fail it must be that your XMLreq is not an object that .open works with...

3.  this tells me that it was not created properly in the first place.

4.  something has to be there or the "!= null" would have failed

5.  I cant seem to find a function call named "new AJAX()", I have found a xmlReq = new XMLHttpRequest(); ..

 

I might be way off but thats what I thought ....

Link to comment
Share on other sites

Sorry about the double post (there's no edit? Yeah, sorry I'm new.)

 

I should clarify my previous post.

The script is now telling me as per my programming that it failed.

that is:

function sendL(){
var usn = document.getElementById('username').value;
var psw = document.getElementById('password').value;
document.getElementById("Login").innerHTML = "Processing...";
XMLreq = new Ajax();
if (XMLreq != null) { //<--this check....
	XMLreq.open("GET", "login.php?username="+usn+"&password="+psw, true); //<--code errors refer to here
	XMLreq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	XMLreq.onreadystatechange = setOutput;
	XMLreq.send(null);
} else { //<--returns false and goes to the else here.
	document.getElementById("Login").innerHTML = "Failed<br />"+
		'<a href="Refresh" onClick="window.reload(); return false;">Refresh?</a>';
}
}
</script>

As stated above, the check to see if XMLreq is null or not fails (i.e. the script finds it to be null) and it gives me the preprogrammed error message that it failed.

So, my new question is: why is the XMLreq null?  What new stupid mistake have I done?

 

As always, help is appreciated, and thanks in advance.

(edit/sidenote: ah..limited time modify links.  I see.)

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.