我有一个基本代码,我正在尝试使用 ajax 将输入框的值发送到 PHP。
我正在将数据从 try.php 发送到 books2.php。
我的 try.php 代码
<!DOCTYPE html>
<html>
<body>
<form method="post">
<input type="number" min="0" id="Q1" name="Q1" method="post"><br>
<input type="number" min="0" id="Q2" name="Q2" method="post"><br>
<input type="number" min="0" id="Q3" name="Q3" method="post">
<input type="submit" id="submit2">
</form>
<h2 id="content"></h2>
<script type="text/javascript" src="jquery-3.4.1.js"></script>
<script>
$("#submit2").click(function(){
var q1 = $("#Q1").val()
var q2 = $("#Q2").val()
var q3 = $("#Q3").val()
$.ajax({
url:"books2.php",
data:{"Quantity1":q1},
success:function(data){
$('#content').html(data)
}
})
})
</script>
</body>
</html>
我的 books2.php 代码
<?php
if(isset($_POST['Quantity1'])){
echo $_POST['Quantity1'];
}else {
echo "failed";
}
?>
先感谢您。
九州编程