Estoy tratando de obtener un formulario para enviar. Estoy usando HTML, JS, PHP y AJAX aquí. Dado que no se enviará, supongo que algo está mal con mi función de inserción, sin embargo, no puedo averiguar cuál es el problema. Cada vez que hago clic en "enviar" nada cambia. Nada se mueve. La información no se agrega.
<!doctype html> <html> <head> <script src="./js/jquery-3.6.0.min.js">. </head> <body> <form onsubmit="return(insertPeople())"> First name: <input type=text id=firstname><br> Last name: <input type=text id=lastname><br> Phone number: <input type=text id=telephonenumber><br> <input type=submit value=submit> </form> <div id=showpeople></div> <script> function insertPeople(){ val = $("#showpeople").val(); $.get("./week7ajax.php",{"cmd":"create", "firstname,lastname,telephonenumber" : val}, function(data){ $("#showpeople").html(data); }); return(false); } function showpeople(){ $.get("./week7ajax.php",{"cmd":""}, function(data){ $("#showpeople").html(data); }); return(false); } showpeople(); </script> </body> </html>Dale una oportunidad a esto. Arreglé algunas citas que faltaban, sangré algunas líneas y eliminé algunos códigos innecesarios.
<form onsubmit="insertPeople(); return false;"> First name: <input type="text" id="firstname"><br> Last name: <input type="text" id="lastname"><br> Phone number: <input type="text" id="telephonenumber"><br> <input type="submit" value="submit"> </form> <div id="showpeople"></div> <script> function insertPeople() { val = $("#showpeople").val(); $.get("./week7ajax.php",{"cmd":"create", "firstname,lastname,telephonenumber" : val}, function(data){ $("#showpeople").html(data); }); } function showpeople() { $.get("./week7ajax.php",{"cmd":""}, function(data){ $("#showpeople").html(data); }); } showpeople(); </script>