0
PHP 처리 페이지를 가져와야하는 AJAX 함수가 호출 된 제출 단추를 클릭하여 데이터를 게시하는 양식이 있습니다.PHP 처리 페이지에서 AJAX 요청을 수신하지 못합니다.
//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();
}
}
브라우저를 게시하고 나서 POST 배열의 변수를 전달하거나 양식과 PHP로 작업 할 때 느낌이 들었습니까? – kay
정확히 - 양식을 제출하는 것이 아니라 사용자 정의 http 요청을 보내므로 직접 처리해야합니다. – weltraumpirat
또한 해당 요청에 대해 "GET"메서드를 사용하고 있습니다. – weltraumpirat