好吧所以我很忙php
代码,当我点击插入按钮,我希望值显示时不重新加载页面。 这里是我的代码:SQL查询插入值,并显示没有重新加载页面
<?php
$connection = mysqli_connect('localhost', 'root', '', 'universitynew');
$sql="SELECT * FROM tblstudent";
$student_records=mysqli_query($connection,$sql);
?>
<html>
<head>
<title></title>
<link rel="stylesheet" type='text/css' href="bootstrap.min.css" />
<script type='text/javascript' src="bootstrap.min.js"></script>
<script type='text/javascript' src="jquery.min.js"></script>
</head>
<body>
<a href="Student.php"class="btn btn-primary active" role="button">Student table</a>
<a href="Degree.php"class="btn btn-primary" role="button">Degree table</a>
<a href="Subject.php"class="btn btn-primary" role="button">Subject table</a>
<a href="assessment.php"class="btn btn-primary" role="button">Assessment table</a>
<a href="student_assessments.php"class="btn btn-primary" role="button">Student Assessment table</a>
<a href="Degree_student.php" class="btn btn-primary" role="button">Student Degree table</a>
<a href="Student_Subject.php"class="btn btn-primary" role="button">Student Subject table</a>
<hr></hr>
<table width="800" border="1" cellpadding="1" cellspacing="1">
<input type="button" name="insertrecords" id="insertrecords" value="Insert Records" />
<span id="success" style="display: none">Successfully Inserted</span>
<div id="response"></div>
<script type="text/javascript">
$(document).ready(function() {
$("#insertrecords").click(function() {
$("#success").show();
$.ajax({
url: "insert_student.php",
type: 'POST',
data: {'action':'submit'},
dataType: 'json',
success: function (data) {
$("#success").hide();
if(data.status=="true"){
$("#response").html(data.universitynew);
}else{
$("#response").html("Error in db query");
}
}
});
});
});
</script>
<h1><a href="insert_student.php".php" class="btn btn-info" role="button">Delete Students</a></h1>
<h1><a href="insert_student.php".php" class="btn btn-info" role="button">Update Students</a></h1>
<tr>
<th>Student ID</th>
<th>Student number</th>
<th>Student name </th>
<th>Student surname</th>
<th>Student course</th>
</tr>
<?php
while ($student=mysqli_fetch_assoc($student_records)){
echo"<tr>";
echo"<td>".$student['student_id']."</td>";
echo"<td>".$student['student_number']."</td>";
echo"<td>".$student['student_name']."</td>";
echo"<td>".$student['student_surname']."</td>";
echo"<td>".$student['student_course']."</td>";
echo"</tr>";
}
?>
我设法做一些jquery
和Ajax的,显示成功插入按钮,它并插入到我的数据库我的问题由不重新加载页面显示的表格出现。任何人都可以帮我做到这一点?
你写了一些j查询代码? –
@Ilyaskarim我为按钮做了,但我不知道如何写jQuery来显示更新后的结果,那是我的问题出现的地方 –