javascript - 在js中插入多个数据,在数据库上
问题描述
我尝试在 JS 中创建一个 Web 应用程序以同时进行多个预订。我已经构建了这段代码:
<script type="text/javascript">
var prezzo = Number(6.50).toFixed(2);
</script>
<a href="#">POSTO 1</a> <span style="display: inline-block;" id="p1"></span> <button onclick="this.style.visibility='hidden'; fp1();">PRENOTA</button> <br>
<a href="#">POSTO 2</a> <span style="display: inline-block;" id="p2"></span> <button id="bp2" onclick="fp2();">PRENOTA</button> <br>
<a href="#">POSTO 3</a> <br>
<a href="#">POSTO 4</a> <br>
</body>
<script>
function fp1() {
document.getElementById("p1").innerHTML = '<input type="text" name="nome" placeholder="Inserisci il tuo Nome" id="nome">' + '<input type="text" name="cognome" placeholder="Inserisci il tuo Cognome" id="cognome">' + prezzo + " " + "€" + " " +'<button id="invia" onclick="invia()" class="btn">INVIA</button>';
}
function fp2() {
document.getElementById("p2").innerHTML = '<input type="text" name="nome" placeholder="Inserisci il tuo Nome" id="nome">' + '<input type="text" name="cognome" placeholder="Inserisci il tuo Cognome" id="cognome">' + prezzo + " " + "€" + " " +'<button id="invia2" onclick="invia()" class="btn">INVIA</button>';
document.getElementById("bp2").style.visibility='hidden';
}
</script>
<script type="text/javascript">function invia()
{
var nome = document.getElementById('nome').value;
var cognome = document.getElementById('cognome').value;
{
$.ajax({
type: 'POST',
url: "insert.php",
data: {"cognome": cognome, "nome":nome, "prezzo":prezzo},
success: function(data){
console.log(nome);
},
error: function(data) {
console.log("Dati non inviati");
}
});
}
问题是当我尝试在 db 上插入数据时,该函数没有采用正确的值,而只是第一个插入的值。
解决方案
推荐阅读
- swift - 当我将协调器与 mvvm-c Rxswift 一起使用时,如何推送新视图?
- android - 找不到 android 的符号 MapStyleOptions
- c# - c# Selenium EdgeOptions 不适用于 Chromium Edge
- python - 在 Pandas 中用列切片删除 NaN 行
- android - 在自己的应用程序中将 AdMob 用于自己的广告(内部),如何?
- jsp - 动态代码评估:JSTL 中的代码注入
- xml - 使用 XSLT 根据给定数字对 XML 文件进行分组
- javascript - 用javascript从数组中重构数据
- sql - SQL - 在日期之间每天计算总 ID
- r - For Loop/Purrr Map 函数基于 R 中的存储值创建新变量