2

I have Ajax like this.

 var idlapkondisi = $('#id_laporan_pemeriksa').val();
  var data = $('#myFormkondisi').serialize();
  $.ajax({
                type:'ajax',
                method:'POST',
                url:url,
                dataType:'json',
                success:function(response){

                },
                error:function(response){
                 console.log(response);
                }
              })  
})

how can i make 2 value in ajax data while the value is a serialize data form ? does the format like this ?

 data:{data,idlapkondisi:idlapkondisi},
Gagantous
  • 432
  • 6
  • 29
  • 69

2 Answers2

2

Use serializeArray instead of serializing.

var idlapkondisi = $('#id_laporan_pemeriksa').val();
var data = $('#myFormkondisi').serializeArray();
data.push({name: "idlapkondisi", value: idlapkondisi});

$.ajax({
    type: 'ajax',
    method: 'POST',
    url: url,
    data: data,
    dataType: 'json',
    success: function(response) {

    },
    error: function(response) {
        console.log(response);
    }
});
Hyyan Abo Fakher
  • 3,497
  • 3
  • 21
  • 35
cgee
  • 1,910
  • 2
  • 22
  • 38
0

Try this to add that value to you payload:

var idlapkondisi = $('#id_laporan_pemeriksa').val();
var data = $('#myFormkondisi').serialize();
data["idlapkondisi"] = idlapkondisi;

Then you can add data to your Ajax call as usual.

Glenn Ferrie
  • 10,290
  • 3
  • 42
  • 73