我正在尝试使用Vue.js和instascan制作QR码扫描仪。我已经完成了扫描部分。现在,我陷入了此过程,必须使用Ajax请求从MySQL检索数据。我似乎无法从输入表单中检索数据。
这是我的HTML代码:
<form id="cont_disp" method="post">
<label class="disptext" style="margin-left: 41%;">Load user credits</label>
<div class="form-group" id="app">
<input v-for="scan in scans" :key="scan.date" hidden :title="scan.content" class="form-control" id="qr_user" name="qr_user" placeholder="Scan User QR Code":value="scan.content" style="width: 15%; font-size: 20px; left: 44%; position: absolute; top: 30%; border: 0; background: transparent;">
</div>
<div class="video-container">
<video id="preview"></video>
</div>
<div class="content-display">
<label class="disptext" style="font-size: 20px;">Username: </label>
<input type="button" name="" class="login" value="Search" style="margin-left: 70%; font-size: 20px;" id="qr_search">
<br /><br />
<label class="disptext" style="font-size: 20px;">Current Balance: </label><input type="text" class="disptext" id="userbal" style="font-size: 20px; left: 44%;"><br /><br />
<label class="disptext" style="font-size: 20px;">Enter credit amount: </label><input type="number" name="loadcred" id="loadcred" style="margin-left: 28%;" required placeholder="Credit amount"><br /><br />
<input type="submit" name="credsub" id="credsub" value="Load Credits" class="login" style="width: 50%; margin-top: 3%;">
</div>
</form>
这是php查询。
include 'dbcon.php';
$qr_user = $_POST['qr_user'];
$query = mysqli_query($con, "SELECT username, credits FROM useracc WHERE username='$qr_user'");
$row = mysqli_fetch_array($query);
echo json_encode($row);
Ajax请求:
$("#qr_search").click(function(){
var qr_user = $("#qr_user").val();
$.ajax({
type: "post",
url: "../Capstone/qrdata.php",
data: formData = {username:qr_user},
success: function(data){
// can't seem to do anything here since I can't fetch any data from php
}
});
});
答案 0 :(得分:1)
更改此:
$qr_user = $_POST['qr_user'];
至:
$qr_user = $_POST['username'];
解决此问题,因为名称不匹配。