|
|
|
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Untitled Document</title>
</head>
<style type="text/css">
span.hidden{
display: none;
}
span.error{
display: inline;
color: black;
background-color: pink;
}
</style>
<script>
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://localhost/xml/checkUserName.php?q=' \\
+ input;
loadXMLDoc(url);
}
}
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);
}
}
}
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();
}
}
}
</script>
<body>
<form action="" method="post">
<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>
</form>
</body>
</html>
Серверный сценарий
<?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="windows-1251" standalone="yes"?>'; ?>
<response>
<method>checkName</method>
<result>
<?php echo nameInUse($_GET['q']) ?>
</result>
</response> | |
|
|
|
|
|
|
|
для: Figaro
(17.11.2005 в 16:01)
| | Бугага :))) Вы издеваетесь? Вы считаете, что кто-то будет хоть капельку вникать в то, что Вы написали? :)) | |
|
|
|