开发者

PHP processing page not receiving AJAX request

I have a form that posts data on click of the submit button an AJAX function is called which should GET the PHP processing page. However the processing page does not seem to getting called or receiving the posted data..the code snippets are below:

//the form


<form name="quicktransfer" action="" method="post">
 <td style="width: 214px;padding-left: 5px;padding-right: 5px; cell-spacing:10px ">
  <dl id='accService'>
          <dt id='accHeader1'>Quick transfer</dt> 
      <dt class='accLinks1'>From.. </dt>
    <dt class='accLinks1'>
<!-- Creates a select drop down box with useres bank account numbers as the options -->

<?php
    $acc_tbl='accounts';
    $cust = $_SESSION['custno'];
    开发者_如何学运维$result = mysql_query("SELECT  accountNo FROM  $acc_tbl WHERE custNo = '$cust'");
    echo '<select name="acc_from">';
    echo "<option value=\" \"></option>";
    while($array = mysql_fetch_assoc($result)) 
    {
    echo "<option value=\"{$array['accountNo']}\">{$array['accountNo']}</option>\n";
    }
    echo '</select>';
?>

<!-- end of the select drop down -->

    </dt>
      <dt class='accLinks1'>To... </dt> <dt class='accLinks1'>

<!-- Creates a select drop down box with useres bank account numbers as the options -->

<?php
    $acc_tbl='accounts';
    $cust = $_SESSION['custno'];
    $result = mysql_query("SELECT  accountNo FROM  $acc_tbl WHERE custNo = '$cust'");
    echo '<select name="acc_to">';

    echo "<option value=\" \"></option>";
    while($array = mysql_fetch_assoc($result)) 
    {
    echo "<option value=\"{$array['accountNo']}\">{$array['accountNo']}</option>\n";
    }
    echo '</select>';
?>

<!-- end of the select drop down -->

    </dt>
    <dt class='accLinks1'>Amount.. </dt>
    <dt class='accLinks1'><input type="input" name="amount" id="amount" size="10"/></dt>
       <dt class='accLinks1'><input type="submit" name="transfer" value="transfer" onclick="loadQuickTransfer()"><br/><br/></dt>
      </dl>     
    </form>


//the AJAX script


function loadQuickTransfer()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("QuickTransfer").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","quicktransfer.php",true);
xmlhttp.send();
}




// the form processing page getting called


if(isset($_POST['transfer']) && $_POST['amount'] == "")
{       
    echo '<b><i>Select account (From..To..)<br/><br/>Type amount to transfer.</i></b>';
}
else
{
    $transFrom = $_POST['acc_from'];
    $transTo = $_POST['acc_to'];
    $amount = $_POST['amount'];
    $acc_tbl = 'accounts';
    $trans_tbl = 'transactions';
    $cust = $_SESSION['custno'];

    $transfer = mysql_query("UPDATE $acc_tbl SET accountBalance = accountBalance -'$amount' WHERE custNo = '$cust' AND accountNo = '$transFrom'");
    if($transfer)
    {
        $transfer2 = mysql_query("UPDATE $acc_tbl SET accountBalance = accountBalance + '$amount' WHERE custNo = '$cust' AND accountNo = '$transTo'");
    }   
    else
    {

        echo '<b>Error.. Could not transfer<br/> Please try again!</b>';
        exit();

    }
        if($transfer2)
        {

            echo '<b>Transfer complete..</b> ';
            exit();
        }

}


I just had a quick look, but it seems you never send any post variables on the XMLHttpRequest.send() call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜