This is a revolution, no more waiting for requests!!
I am totally new to this and the example is not working for me =( can someone help me?? pleaseeeee
I created a file called revolution.html on my web server and another revolution.php. Mozilla doesn't do anything after I leave(onblur) the input form and explorer gives me a javascript error(it can't detect the object of the input box after I leave the box it says "Object expected")
HTML BELOW
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>This is a revolution</title>
<style type="text/css">
<!--
span.hidden{
display: none;
}
span.error{
display: inline;
color: black;
background-color: pink;
}
--->
</style>
<SCRIPT LANGUAGE="JavaScript">
var req;
function loadXMLDoc(url)
{
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}
function processReqChange()
{
// only if req shows "complete"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
// ...processing statements go here...
response = req.responseXML.documentElement;
method =
response.getElementsByTagName('method')[0].firstChild.data;
result =
response.getElementsByTagName('result')[0].firstChild.data;
eval(method + '(\'\', result)');
} else {
alert("There was a problem retrieving the XML data:\n" + req.statusText);
}
}
function checkName(input, response)
{
if (response != ''){
// Response mode
message = document.getElementById('nameCheckFailed');
if (response == 1){
message.className = 'error';
}else{
message.className = 'hidden';
}
}else{
// Input mode
url =
'http://revolution.php?q=' + input;
loadXMLDoc(url);
}
}
</SCRIPT>
</head>
<BODY >
<input id="username" name="username" type="text"
onblur="checkName(this.value,'')" >
<span class="hidden" id="nameCheckFailed">
This name is in use, please try another.
</span>
</body>
</html>
PHP file
<?php
header('Content-Type: text/xml');
function nameInUse($q)
{
if (isset($q)){
switch(strtolower($q))
{
case 'drew' :
return '1';
break;
case 'fred' :
return '1';
break;
default:
return '0';
}
}else{
return '0';
}
}
?>
<?php echo '<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>'; ?>
<response>
<method>checkName</method>
<result><?php
echo nameInUse($_GET['q']) ?>
</result>
</response>
|