php - 通过 href 方法将复选框的值发送到 control.php 文件
问题描述
我的网络摄像头有一个 control.php 文件,我可以使用图像映射的 href 链接向它发送命令,如下所示:href="command.php?cmd=1"。在 control.php 中有一个睡眠定时器,它会在 1 秒后停止相机的移动。一切正常。现在,我想在网络摄像头流媒体页面中添加一个复选框,并且除了命令之外,还希望将复选框的值发送到 command.php。它会在一秒钟后停止凸轮的移动,取决于复选框的值。我在 php 甚至 JS 中都尝试过,但我太愚蠢了,无法完成。非常感谢任何帮助!干杯,福尔克
解决方案
您可以在复选框上使用 javascript 事件 onclick() 并对第二个 PHP 脚本进行 AJAX 调用。随着this
您将复选框对象及其数据作为参数传递。
<input type='checkbox' onclick='moveCamera(this);'>
<script>
function moveCamera(checkbox) {
var http = new XMLHttpRequest();
var url = 'command.php';
var params = 'cmd=1&checked=' + checkbox.checked;
http.open('POST', url, true);
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
// Here you can put code that will be executed after the call is complete
}
}
http.send(params)
}
</script>
现在您可以checked
像cmd
在第二个 php 脚本中一样访问。
推荐阅读
- java - 获取对象标签的速度比 JVMTI GetTag 更快
- ruby-on-rails - rspec :type 的有效值是什么?
- html - 使用 HTML/CSS 将内容缩小到可打印页面
- html - 如何将 div 作为一个元素加载?
- mysql - 查询后替换内容
- java - Tomcat Monitor App 中对 Java 选项的更改是否会在运行时持续存在?
- javascript - 在 HTML5 中创建可拖动和可缩放的网格
- scala - Scala中Case类的理解
- ios - iphone 导出 - 如何保持视频的 FPS > 30 FPS
- kubernetes - 将 kubelet 指向附加的磁盘