Darth,
I'll break down the code and hopefully you should be able to follow the flow a bit better. It can seem quite daunting at first.
Firstly to explain what AJAX does. Simply put AJAX uses javascript to send a request to a page and return the result. The return from this would be whatever is on the page. While all this happens the user can still use the page and is not aware of what is happening in the background. An example may help clarify this.
First you need to create a request variable:
As ever IE and everything else use different items to implement the request so a quick if loop to determine the type of browser and then set req to the correct type:
-
function makeRequest(password){
-
req=null;
-
-
if (window.XMLHttpRequest){
-
//Everything but IE
-
req = new XMLHttpRequest();
-
}
-
else if(window.ActiveXObject){
-
//IE
-
req = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
If req is not null then it has been set correctly so process the request.
-
if (req!=null){
-
var url;
-
url="/url/for/passwordtest.aspx?pw="+password;
-
req.onreadystatechange=state_Change;
-
req.open("GET",url,true);
-
req.send(null);
-
}
-
}
-
The url variable is the address for the page that will read from the text file and look for the password submitted in the pw parameter of the querystring. Whenever the onreadystatechange of the req object changes a function called state_Change will be called:
-
function state_Change(){
-
// if xmlhttp shows "loaded"
-
if (req.readyState==4){
-
// if "OK"
-
if (req.status==200){
-
var response;
-
response=req.responseText;
-
//handle response.
-
}
-
}
-
}
-
The complete javascript in one block is:
-
-
var req;
-
-
function makeRequest(password){
-
-
req=null;
-
-
if (window.XMLHttpRequest){
-
//Everything but IE
-
req = new XMLHttpRequest();
-
}
-
else if(window.ActiveXObject){
-
//IE
-
req = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
-
if (req!=null){
-
var url;
-
url="/url/for/passwordtest.aspx?pw="+password;
-
req.onreadystatechange=state_Change;
-
req.open("GET",url,true);
-
req.send(null);
-
}
-
}
-
-
function state_Change(){
-
// if xmlhttp shows "loaded"
-
if (req.readyState==4){
-
// if "OK"
-
if (req.status==200){
-
var response;
-
response=req.responseText;
-
//handle response.
-
}
-
}
-
}
-
The variable response is used so that the response is in a variable. It is populated from the responseText property of the request. Code would need to be added to handle the response.
The only other thing required would be to write the aspx page that the request is being sent to. I won't go through all the code but it should flow something like:
-
'set a variable for the password value
-
Dim pw = request.QueryString("pw")
-
-
'test against the file
-
if matched then
-
response.write("true")
-
else
-
response.write("false")
-
end if
-
The response value in the javascript would then be true or false depending on the result. Only the one word would be required on the aspx page (no HTML needed). Hope this helps