我现在已经搜索了几个小时以了解我如何才能做到这一点,但遗憾的是一切都无济于事。
我正在尝试发送输入的信息,以便它可以通过MySQL运行并获取信息,然后在屏幕上的表格中回显。
问题(据我所知)必须使用我的JQuery代码:
$("#btnCheckNoteIDs").click(function(){
var noteUser = $("#noteUser").val();
var noteDate = $("#noteDate").val();
$("#LoadNoteIDs").load('check_noteIDs.php?noteDate='+noteDate + "¬eUser="+noteUser);
});
我的php代码如下:
$result = mysqli_query($con,"
SELECT ID, ClientID, Note, ToDoDate, CaseID
FROM ToDoNotes
WHERE ToDoStatus='0' and Deleted='0' and `ToDoDate`='".$_GET['noteIDsDate']."' and User='".$_GET['noteIDsDate']."'");
while($row = mysqli_fetch_array($result))
{
$ID = $row['ID'];
$ClientID = $row['ClientID'];
$Note = $row['Note'];
$ToDoDate = $row['ToDoDate'];
$CaseID = $row['CaseID'];
}
?>
<table class="table table-striped">
<thead>
<tr>
<th>Note ID</th>
<th>Client ID</th>
<th>Case ID</th>
<th>Note</th>
<th>To Do Date</th>
</tr>
</thead>
<tbody>
<tr>
<td><? echo $noteID; ?></td>
<td><? echo $ClientID; ?></td>
<td><? echo $CaseID; ?></td>
<td><? echo $Note; ?></td>
<td><? echo $ToDoDate; ?></td>
</tr>
</tbody>
</table>
这里有人可以提供任何帮助吗?任何帮助将不胜感激!
谢谢!
答案 0 :(得分:0)
假设您有如下的form.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form method="post" id="btnCheckNoteIDs">
<label> User</label>
<input type="text" name="user" id="noteUser"><br>
<label>Date</label>
<input type="date" name="date" id="noteDate"><br>
<input type="submit" value="submit">
</form>
<br>
<div id="LoadNoteIDs"></div>
</body>
</html>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"
integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
crossorigin="anonymous"></script>
<script>
$(document ).ready(function() { //make sure document is ready
$('#btnCheckNoteIDs').submit(function(e){
e.preventDefault();//to prevent default behaviour
var noteUser = $("#noteUser").val();
var noteDate = $("#noteDate").val();
if(noteUser==undefined){
alert('No noteuser');
return false;
}else if(noteDate==undefined){
alert('no note date');
return false;//stop sending
}
//to convert %2F, use decodeURIComponent
var param= 'noteDate='+decodeURIComponent(noteDate) + '¬eUser='+noteUser;
$.ajax({
url: "check_noteIDs.php",
data: param,
type: "post",
success: function(data){
$('#LoadNoteIDs').html(data);
}
});
});
});
</script>
在check_noteIDs.php中的,它必须位于放置form.php的同一文件夹中
require_once "dbconfig.php";
$user= isset($_REQUEST['noteUser'])? $_REQUEST['noteUser']:'';
$date = isset($_REQUEST['noteDate'])? date('Y-m-d', strototime($_REQUEST['noteDate'])):'';
//You can validate here.
$result = mysqli_query($con," SELECT ID, ClientID, Note,
ToDoDate, CaseID
FROM `ToDoNotes`
WHERE `ToDoStatus`='0' AND `Deleted`='0'
AND `ToDoDate`='$date'
AND `User`='$user'");
$row = mysqli_fetch_assoc($result);
<table class="table table-striped">
<thead>
<tr>
<th>Note ID</th>
<th>Client ID</th>
<th>Case ID</th>
<th>Note</th>
<th>To Do Date</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $row['ID']; ?></td>
<td><?php echo $row['ClientID']; ?></td>
<td><?php echo $row['CaseID']; ?></td>
<td><?php echo $row['Note']; ?></td>
<td><?php echo $row['ToDoDate']; ?></td>
</tr>
</tbody>
</table>
<?php
mysqli_free_result($result);
mysqli_close($con);
?>
答案 1 :(得分:0)
我认为您的问题是表单中的提交按钮,在脚本执行之前提交表单。如果是这种情况,您需要更新脚本,如下所示:
$("#btnCheckNoteIDs").click(function(event){
event.preventDefault();
var noteUser = $("#noteUser").val();
var noteDate = $("#noteDate").val();
$("#LoadNoteIDs").load('check_noteIDs.php?noteDate='+noteDate + "¬eUser="+noteUser);
});