stockton 10 Light Poster

I have the following html

<html>
<head>
<title>Voucher Usage</title>
<script language="JavaScript" type="text/javascript" src="js/voucher.js"></script>
</head>
<body onLoad="document.VU.Number.focus()">
<form name="VU" id="VU" method="post" >
Voucher Number: <input type="text" size="20" maxlength="20" id="Number" name="Number" onChange='submit_click(this.value)'><br />
<center>
<div id="loadingNode"></div>
</center>
</body>
</html>
<script language=javascript>
function submit_click(VoucherNumber)
    {
    if ((VoucherNumber[0] == ";") && (VoucherNumber[strlen(VoucherNumber) -1] == "?"))
        {
        VoucherNumber.substr(1,(strlen(VoucherNumber) - 2));
        }
    progExe("voucher.php?Number=" + VoucherNumber);
    }
</script>

and my Ajax/javascript looks like :-

function getXMLHttpRequest ()
    {
    try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {};
    try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {};
    try { return new XMLHttpRequest(); } catch(e) {};
    return null;
    }

// Make the XMLHttpRequest object
        var xhr = getXMLHttpRequest();
//        setTimeout(progExe(),500);

function progExe(CommandString)
        {
//        alert("CommandString = " + CommandString);
        xhr.open("GET", CommandString, true);
        xhr.onreadystatechange = ServerResponse;
        xhr.send(null);
        }

function ServerResponse()
        {
//        alert("entered ServerResponse()");
/* The full list of the readyState values is as follows:
    * 0 (uninitialized)
    * 1 (loading)
    * 2 (loaded)
    * 3 (interactive)
    * 4 (complete)
 */
        if(xhr.readyState == 0)
            {
            document.getElementById("loadingNode").innerHTML = "Uninitialized........";
            }
        else
        if(xhr.readyState == 1)
            {
            document.getElementById("loadingNode").innerHTML = "Loading........";
            }
        else
        if(xhr.readyState == 2)
            {
            document.getElementById("loadingNode").innerHTML = "Loaded........";
            }
        else
        if(xhr.readyState == 3)
            {
            document.getElementById("loadingNode").innerHTML = "Interactive........";
            }
        else
        if(xhr.readyState == 4)
            {
            if (xhr.status == 200)
                {
                alert(xhr.responseText);
                }
            else
                {
                alert(xhr.status + " Text= " + xhr.responseText + " XML= " + xhr.responseXML);
                }
            }
        }

and the php is :-

<?php
require_once('includes/configuration.php');     // database connect script & the rest.

$Message = "";
if (empty($_GET["Number"]))
    {
    $Message .= "Invalid voucher number!";
    }
    else
    {
    DBConnect();        // Connect to Events database
    $VoucherNum = $_GET["Number"];
    $SQL = 'SELECT * FROM Voucher WHERE Number='.$VoucherNum;
    $rs = mssql_query($SQL, $link);
    $Count = 0;
    while ($row = mssql_fetch_array($rs))
        {
        $EventName = $row['Number'];
        $Datum     = $row['DatePresented'];
        $Message  .= "Number ".$EventName." previously processed on ".$Datum;
        ++$Count;
        }
    if ($Count == 0)
        {
        $Datum = date("Y-m-d H:i:s");    /* 2006-03-17 23:22:32 */
        $SQL = sprintf("INSERT INTO Voucher(Number, DatePresented) VALUES ('%s','%s')",$VoucherNum, $Datum);
        $rs = mssql_query($SQL, $link);
        $Message .= "Number ".$EventName." successfully registered on ".$Datum;
        }
    DBDisConnect();     // Disconnect from Events database
    }
echo $Message;
return $Message;
?>

All very simple stuff really. But what is beating me is that the response I get when the above is run is:-
0 Text=  XML= null
from the last alert in the javascript file.
Why would the response be 0 rather than 200?
This especially as xhr.readyState == 4.
Please tell me what I have done wrong.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.