drkjzk3359 2019-05-06 01:52
浏览 33

我怎样才能清除输入字段但将数据推送到数据库?

I'm trying to clear my input field's ,but when i clear them php pushes empty string to my database .could someone help me?

this is my code.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="style.css">
    <title>Document</title>
     <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script>
      $(function () {

        $('form').on('submit', function (e) {

          e.preventDefault();

          $.ajax({
            type: 'post',
            url: 'phpAdd.php',
            data: $('form').serialize(),
            success: function () {
              alert('form was submitted');
            }
          });

        });

      });

      function submitForm(){
          var form = document.getElementById("myForm");
          form.reset(); 
          $('#firstname').focus();
    }
    </script>
</head>
<body>
    <center>
        <form action="phpAdd.php" method="post" id="myForm">
        <h1>Please enter your info.</h1>
        First Name: <input type="text" name="firstname" id="firstname" class="firstname"><br>
        Last Name:  <input type="text" name="lastname" id="lastname" class="lastname"> <br>
        <input type="submit" value="SUBMIT" class="SUBMIT" onclick="submitForm()">
       </form>
    </center>
</body>
</html>

how could i clear the field's after it pushes the data to php?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思