Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: 'append' called on an object that does not implement interface FormData

$(document).on('submit','#form_pem', function(event){
            event.preventDefault();
            var kodebayar = $('#kodebayar').val();
            var nama = $('#nama').val;
            var harga = $('#harga').val;
            var postData = new FormData(this);

            if(kodebayar != '' && nama != '' && harga != ''){
                $.ajax({
                    url:"<?=site_url('bpem/user_action')?>",
                    method:"POST",
                    data:postData,
                    contentType:false,
                    proccessData:false,
                    success: function(data)
                    {
                        alert(data);
                        $('#form_pem')[0].reset();
                        $('#modalpem').modal('hide');
                        dataTable.ajax.reload();
                    }

                });

            }
            else{
                alert("Silahkan isikan semua data!");
            }
        });

this is my JS

<div class="modal fade text-xs-left" id="modalpem" tabindex="-1" role="dialog" aria-labelledby="myModalLabel35" aria-hidden="true">
                                      <div class="modal-dialog modal-sm">
                                        <form method= "post" id="form_pem">
                                        <div class="modal-content">
                                          <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                              <span aria-hidden="true">&times;</span>
                                            </button>
                                            <h3 class="modal-title text-xs-center">Tambah Biaya Pembayaran</h3>
                                          </div>
                                            <div class="modal-body">
                                                <fieldset class="form-group floating-label-form-group">
                                                    <label for="Kode">Kode <span class="required">*</span></label>
                                                    <input type="text" class="form-control" name="kodebayar" id="kodebayar" placeholder="Kode Pembayaran">
                                                </fieldset>
                                                <fieldset class="form-group floating-label-form-group">
                                                    <label for="nama">Nama <span class="required">*</span></label>
                                                    <input type="text" class="form-control" name="nama" id="nama" placeholder="Nama Pembayaran">
                                                </fieldset>
                                                <fieldset class="form-group floating-label-form-group">
                                                        <label for="projectinput7">Biaya Perbulan <span class="required">*</span></label>
                                                        <div class="input-group">
                                                            <span class="input-group-addon">Rp.</span>
                                                            <input type="number" class="form-control" placeholder="Biaya Perbulan" aria-label="Amount (to the nearest dollar)" name="harga" id="harga">
                                                            <span class="input-group-addon">.00</span> 
                                                        </div>
                                                </fieldset>
                                            </div>
                                            <div class="modal-footer">
                                                <input type="reset" class="btn btn-grey" value="Bersihkan">
                                                <input type="submit" class="btn btn-warning" name="action" id="action" value="Tambah">
                                            </div>
                                        </div>
                                        </form>
                                      </div>

                                    </div>

and this is the view. But i got an error like

TypeError: 'append' called on an object that does not implement interface FormData.

Did i forget something to add? What should i do? thankyou for your help

like image 234
Fiona Avatar asked Mar 21 '17 09:03

Fiona


1 Answers

Need a correction for typo :)

proccessData:false

should be

processData: false

To avoid FormData errors make sure that the ajax options must be like

$.ajax({
    url : "url",
    type: "POST",
    data : postData,
    processData: false,
    contentType: false,
    success:function(data, textStatus, jqXHR){
        //
    },
    error: function(jqXHR, textStatus, errorThrown){
        //if fails     
    }
});
like image 83
Jyothi Babu Araja Avatar answered Oct 17 '22 12:10

Jyothi Babu Araja