У меня есть форма, которая публикует данные при нажатии кнопки отправки, вызывается функция AJAX, которая должна ПОЛУЧИТЬ страницу обработки PHP. Однако страница обработки, похоже, не вызывается и не получает опубликованные данные. Фрагменты кода приведены ниже:

//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();
        }

}
0
kay 14 Апр 2011 в 03:10

1 ответ