Jump to content

I am not getting the expected reply?


stockton

Recommended Posts

I have the following html

<html>
<head>
<title>Voucher Usage</title>
<script language="JavaScript" type="text/javascript" src="js/Diva.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(VoucherNumber);
    }
</script>

 

and the 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)
        {
        var xhr = getXMLHttpRequest();
        alert("CommandString = " + CommandString);
        var url="voucher.php";
        url=url+"?Number="+CommandString;

        xhr.open("GET", url, 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);
                }
            }
        }

 

the php on the server looks like:-

 

<?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   = $EventName." already 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   = $EventName." successfully registered on ".$Datum;
        }
    DBDisConnect();     // Disconnect from Events database
    }
echo $Message;

?>

 

Please tell me what I have done wrong as I am not getting the $Message appearing in the alert() where I expect it to appear.

The user is to scan in the voucher number and the system is to verify if the voucher has previously been scanned or not.

Link to comment
https://forums.phpfreaks.com/topic/194486-i-am-not-getting-the-expected-reply/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.