javascript - 如何从 HTML 选择中获取选定的文本以将其发送到数据库
问题描述
我有这个选择,值来自数据库
<select id="construido" name="construido" class="form-select form-select-sm" aria-label=".form-select-sm example">
<option id="construido-0" selected class="form-control"></option>
<option id="construido-1" value="1"> </option>
<option id="construido-2" value="2"> </option>
</select>
但现在我正在尝试使用 ajax php 将选定的文本发送到另一个表。我试过了,但我construidoSelected
只能在函数内部访问
$(document).on('change', '#construido', function () {
let construidoSelected = $("#construido option:selected").text()
});
let start = 0, url = "http://localhost:8077/connectpost/validations/sendinterview.php";
$(document).ready(function () {
$('#form_interview').submit(function (e) {
$.post(url, {
fuente:"",
construido:"",
recibir: $("#recibir-agua").val(),
horas: $("#horas-agua").val(),
});
$("#recibir").val("");
$("#horas").val("");
return false;
})
});
解决方案
推荐阅读
- python - 用相同的值填充两个 pandas 列值之间的值
- ios - 为什么我的 UITextField 没有出现(尝试使用自动约束),没有 CGRect
- ios - 将多个图像上传到 Firebase
- python - 如何修复“Nginx 被禁止”的错误?
- javascript - 在 Ajax 中实现这个精确的 PHP foreach 功能?
- java - 如何为 ResultSet 应用 MapReduce?
- java - 从服务器 url 在 android 应用程序中显示 pdf 文件,而无需授予下载该文件的权限
- c++ - C++ 二维向量导致缓冲区溢出
- javascript - React Native 无法构建
- r - 如何获得每周。来自一年的每日数据集的季度和月度计数