如何在javascript中输入方法Post

时间:2017-12-29 14:05:06

标签: javascript php jquery post

我在javascript代码中输入了代码,但是使用方法GET

$('#frm-example').on('submit', function(e){ //on submit
    var judul   = document.getElementById("judul_survey").value;
    var kategori= document.getElementById("id_kategori").value;
    var target  = document.getElementById("viewSelector").value;
    window.location.href = "<?php echo base_url() ?>survey/simpan_survey?judul_survey="+judul+"&id_target="+target+"&id_kategori="+kategori;
}

我想用方法Post改变,请帮帮我 注意:我在php进程中使用了$ _POST方法

感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用 $.post 方法使用POST方法发布数据。

$('#frm-example').on('submit', function(e){ 

    $.post("survey/simpan_survey",
      { judul_survey: judul, id_target: target }, 
     function(data, status){
        alert("Data: " + data + "\nStatus: " + status);
    })

   });