Home > database >  ajax type:"POST" but post is empty
ajax type:"POST" but post is empty

Time:01-24

// Kirim permintaan AJAX ke server
  $.ajax({
    url: "getData",  // URL yang akan dituju
    type: "POST",       // Tipe permintaan
    data: {             // Data yang akan dikirim ke server
      no_spk: $("#input_nomor_spk").val()
    },


    success: function(result) {  // Fungsi yang akan dijalankan jika permintaan berhasil
      // Isi form dengan data yang diterima dari server
      $("#input_rujuk_sp1").val(result.no_surat_text);
      // dst.
    }
  });

I have set method type as post but in my Controller getData() I just get values either but not in $_POST.

  $no_spk = $this->input->post("no_spk");

  // Ambil data dari database
  $data = $this->m_surat->cari($no_spk);

  // Kembalikan hasil dalam format JSON
  echo json_encode($data);

CodePudding user response:

Press F12 to open inspect element then perform the transaction, check your payload, to see if javascript is passing a data from post ajax request enter image description here

  • Related