在ajax中输入必需的属性形式不起作用

时间:2019-04-13 15:49:47

标签: php jquery ajax

如果我在单击提交时更改数据而没有插入提交数据,而在单击时成功插入,这是我的代码,那么当我使用Ajax提交数据时,属性要求不起作用。这是在表单向导#jquery #Codeigniter

<form action="#">
   <div class="form-group row">
      <div class="col-sm-7">
         <h3 class="wizard-title">Data Surat</h3>
      </div>
   </div>
   <div class="form-group row">
      <label class="col-12 col-sm-3 col-form-label text-left text-sm-right">Nomor</label>
      <div class="col-12 col-sm-8 col-lg-6">
         <input class="form-control" type="text" required placeholder="Nomor Surat" id="nomor" name="nomor">
      </div>
   </div>
   <div class="form-group row">
      <label class="col-12 col-sm-3 col-form-label text-left text-sm-right">Tanggal</label>
      <div class="col-12 col-sm-8 col-lg-6">
         <input class="form-control" type="date" required name="tanggal" id="tanggal" placeholder="Tanggal">
      </div>
   </div>
   <div class="form-group row">
      <label class="col-12 col-sm-3 col-form-label text-left text-sm-right">Tujuan</label>
      <div class="col-12 col-sm-8 col-lg-6">
         <Textarea class="form-control" required name="tujuan" id="tujuan" ></Textarea>
      </div>
   </div>
   <div class="form-group row">
      <div class="offset-sm-2 col-sm-10">
         <!-- <input type="button" onclick="myFunction()" class="btn btn-secondary btn-space" value="Reset"> -->
         <button class="btn btn-primary btn-space wizard-next" id="btn_save" type="submit" data-wizard="#wizard1">Selanjutnya</button>
      </div>
   </div>
</form>

这是我的脚本ajax

<script type="text/javascript">
    $(document).ready(function() {
        //Save product
        $('#btn_save').on('click', function(e) {
            e.preventDefault();

            if(! $form.valid()) return false;
            var $form = $(this);
            var nomor = $('#nomor').val();
            var tanggal = $('#tanggal').val();
            var tujuan = $('#tujuan').val();
            $.ajax({
                type: "POST",
                url: "<?php echo site_url('users/bendahara/sp/save')?>",
                dataType: "JSON",
                data: {
                    nomor: nomor,
                    tanggal: tanggal,
                    tujuan: tujuan
                },
                success: function(data) {
                    $('[name="nomor"]').val("");
                    $('[name="tanggal"]').val("");
                    $('[name="tujuan"]').val("");
                    // show_product();
                }
            });
            return false;
        });

    });
</script>

也许你知道

必需的工作

0 个答案:

没有答案