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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.