jquery - jQuery 不发送 POST 数据
问题描述
我有一个页面 quiz.php,它显示测验问题。我想使用 AJAX 发送问题类型的数据。我返回到同一页面,其中加载了一个新问题。
现在您看到的是,在提交时我创建了一个alert
just for while 编码以检查 ID 是否正确,它们是正确的。在此警报之后,我想设置 POST。现在我只是将 Id 发送到里面box1
,但最后所有四个都应该在那里。
当我的页面重新加载时,我想查看使用的 ID
$test = isset($_POST['box']);
var_dump($test);
请参阅下面的代码
<?php
//logtime.php
$test = isset($_POST['box']);
var_dump($test);
var_dump($_REQUEST);
//rest of code that uses $uid
?>
<form method="POST" autocomplete="off" id="form">
<?php showPhoto($question[1], $question[0]); ?>
<div class="row createWhitespaceBottom" id="fotoblok">
<div class="col-sm-12 col-md-offset-3">
<div class="input-group">
<input type="hidden" name="questionId" class="form-control" id="questionId" value="<?php echo $question[0]; ?>">
<input type="hidden" name="questionType" class="form-control" id="questionType" value="<?php echo $question[1]; ?>">
</div>
</div>
</div>
<div class="col-sm-3">
<div class="dragBox" id="box1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
</div>
<div class="col-sm-3">
<div class="dragBox" id="box2" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
</div>
<div class="col-sm-3">
<div class="dragBox" id="box3" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
</div>
<div class="col-sm-3">
<div class="dragBox" id="box4" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
</div>
<span class="input-group-btn createWhitespaceTop">
<button type="submit" onclick="myFunction()" id="antwoordblok2" class="btn btn-primary">Opslaan</button>
</div>
</form>
</div>
$(document).ready(function() {
$("form").submit(function() {
var box1 = $("#box1 :first-child").attr('id');
var box2 = $("#box2 :first-child").attr('id');
var box3 = $("#box3 :first-child").attr('id');
var box4 = $("#box4 :first-child").attr('id');
alert(box1 + " " + box2 + " " + box3 + " " + box4);
$.ajax({
type: 'POST',
url: 'quiz.php',
data: {
box: box1
},
});
});
});
解决方案
<button type="button" onclick="myFunction()" id="antwoordblok2" class="btn btn-primary">Opslaan</button>
将类型“提交”更改为“按钮”并将其重定向或重新加载成功。
它将异步调用 ajax,当调用成功时,您可以采取所需的操作。
推荐阅读
- azure - 如何在 Azure 门户中使用 PowerShell 为 Outlook 365 创建新的 API 连接器?
- python - 如何使用 python 的 socket 模块连接到 Socks4 代理?
- vb.net - 问题学习 For...Next 循环
- python - 为什么在pycharm控制台中执行任意语句时会调用`__getattr__`?
- firebase - 授予阅读和使用照片的权限
- javascript - glb 没有出现在 three.js 中
- ado.net - 我可以在表值 SqlParameter 中放入的行数是否有限制?
- c# - 来自基类的 C# 泛型方法
- visual-studio - 构建 VS 扩展需要哪些 Visual Studio 工作负载?
- java - JVM 提交的堆内存大于 Xmx