gpt4 book ai didi

javascript - 表单不重定向到新页面

转载 作者:行者123 更新时间:2023-11-29 21:09:42 25 4
gpt4 key购买 nike

getStudents.js

$("#submit").click(function(){
$.ajax({
url: "displayStudents.php?branchCode=1",
datatype:"JSON",
success: function(obj){
$("table").append("<form method='POST' action='markAttendance.php'> <tr><th>Roll No</th> <th>Name</th><th colspan='2'>Attendance</th></tr>");
for(var i=0; i<obj.length; i++){
$("table").append(
"<tr>"+
"<td>"+obj[i].RollNo+"</td>"+
"<td>"+obj[i].Name+"</td>"+
"<td><input type='radio' name='mark["+i+"]' value='Present'>Present" +
"<input type='radio' name='mark["+i+"]' value='Absent' checked>Absent</td>" +
"</tr>"
);
}
$("table").append("<tr><td><button type='submit' name='submitMark' id='submitMark'>Mark Attendance</button></td></tr></form>");
$("#submit").hide();
}
})
});

在 html 文件中有一个表格和按钮,其 id 为提交。我正在正确获取 json,它也正确显示。但是每当我点击标记出勤按钮时,它都不会重定向到 markAttendance.php。

最佳答案

尝试这样调用:

$('body').on('click',"#submit",function(){

因为它是 AJAX,页面不会在 displayStudents.php 上重定向。将对页面进行异步调用。

您可以在检查工具 --> 网络选项卡上进行跟踪。

而不是 <table><form></form></table>结构,做<form><table></table></form>

关于javascript - 表单不重定向到新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42291821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com