Sign In/My Account | View Cart  
advertisement

Article:
 Very Dynamic Web Interfaces
Subject: Probelm...
Date: 2005-10-15 06:34:03
From: fretoune

Hello there,


I'm sorry to say that I'm just unable to make the script work. It's been a couple of hours since it's driving me crazy... I've read over and over again, everything looks like what is above.
I've tried without the quotes around (response == '1'), I've tried to put my files in the same folders... No way to work (I've got Firefox 1.0.7


Sorry to post all my code, but if you can help, I'd greatly appreciate...


file : loadxmldoc.js :
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';
alert('ok');
}else{
message.className = 'hidden';
alert('pas ok');
}
}else{
// Input mode
url = 'scripts/checkUserName.php?q=' + input;
loadXMLDoc(url);
}
}


file checkusername.php
<?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>
and the form has the span and the style required, with the call to the checkName function...


Sorry for my incompetence... and thanks if you can help.


Fred.


PS : if I make an error in the name of the file checkusername.php, I've got the alert fine... so I guess my problem is in the response part ..?


Previous Message Previous Message   Next Message Next Message


Full Text Titles Only Newest First

Sponsored By: