ボタンをクリックした後、ページに全く反応がありません。フィードバックなしPHPとAJAX "POST"
postメソッドを使用して、変数をajaxファイルに取得します。ここにコードがあります。
オリジナル.phpは、値を取得するフォームを含むファイルであり、ajaxファイルに送信されます。
stockProcess.phpは、SQLプロセスを実行してデータベースの在庫を更新するajaxファイルです。
original.php
<div id='status'></div>
<input type='number' name='quantity' style='max-width:50px' id='quantity'/>
<button class='btn btn-xs btn-success' onClick='add('pen100')'>
<i class='ace-icon fa fa-plus bigger-120'></i>
</button>
<script type="text/javascript">
function add(serialNo)
{
var quantity = document.getElementById("quantity").value;
var type = "add";
if (quantity == null)
{
document.getElementById("status").innerHTML = "<p><b><font color='red'>PLEASE INPUT A VALUE</font></b></p>";
}
else if (quantity < 0)
{
document.getElementById("status").innerHTML = "<p><b><font color='red'>WRONG VALUE<br />PLEASE ENTER VALUE LARGER THAN 0</font></b></p>";
}
else
{
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 (this.readyState == 4 && this.status == 200)
{
document.getElementById("status").innerHTML = this.responseText;
}
};
xmlhttp.open("POST","stockProcess.php?serialNo="+serialNo+"&quantity="+quantity+"&type="+type, true);
xmlhttp.send();
}
}
</script>
stockProcess.php
<?php
$serialNo = $_POST['serialNo'];
$quantity = $_POST['quantity'];
$type = $_POST['type'];
if ($type == "add")
{
$newQ = $quantity + 50;
$sqlAdd = "UPDATE medicinestock SET quantity=$newQ WHERE serialNo='$serialNo'";
$queryAdd = $conn -> query($sqlAdd);
if ($queryAdd == TRUE)
{
echo "<b><p><font color='green'>STOCK HAS BEEN UPDATE</font></p></b>";
}
else
{
$err = $conn -> error;
echo "<b><p><font color='red'>SYSTEM ERROR : $err</font></p></b>";
}
}
?>
単純なajaxのinstedはjQuery ajaxを使用することができます.. !! –
代わりにこのメソッドを使用したい場合はどうすればいいですか?どの部分を修正する必要がありますか? – Asyraf
あなたはjQueryについて考えていますか? –