-2

I cannot post data. The response is 404 and the url response is undefined.

Here is my code:

//model
public function lihat_nama_method($nama_fgwtmethod) {
    $query = $this->db->select('*');
    $query = $this->db->where(['nama_fgwtmethod' => $nama_fgwtmethod]);
    $query = $this->db->get($this->_table);
    return $query->row();
}
//Controller
public function get_all_method(){
    $data = $this->m_fgwttesting->lihat_nama_method($_POST['nama_fgwtmethod']);
    echo json_encode($data);
}
<script>
$("#id_fgwtmethod").on("change", function(){
    if($(this).val() == '') reset()
    else {
        const url_get_all_method = $("#content").data("url") + "/get_all_method"
        $.ajax({
            url: url_get_all_method ,
            type:'POST',
            dataType: 'json',
            data: {id_fgwtmethod: $(this).val()},
            success: function(data) {
              $('select[name="id_fgwtmethod"]').val(data.id_fgwtmethod)
              $('button#tambah').prop('disabled', false)
            }
        })
    }
})
</script>

The result of code above:

enter image description here

ADyson
  • 57,178
  • 14
  • 51
  • 63
iso ayu
  • 1
  • 1
  • 4
    The problem seems to be that `$("#content").data("url")` contains the wrong data. But we cannot see how that variable is populated, you have not shown it. And what do you believe should be the correct URL instead? Please provide a [mre] of the issue. See also [ask]. You can [edit] your post. Thankyou. – ADyson Sep 01 '23 at 07:04
  • 3
    Well clearly `$("#content").data("url")` returned `undefined` here. – CBroe Sep 01 '23 at 07:04
  • I for one have always been having troubles with jquery `data()`, maybe `$("#content").attr("data-url")` might work. (there are explanations here: https://stackoverflow.com/questions/25876274/jquery-data-not-working) – GrafiCode Sep 01 '23 at 08:12
  • 1
    @GrafiCode I doubt that's the issue. It is clearly finding a value, otherwise there would be nothing between `index.php/` and `/get_all_method` in the generated URL. The issue, I would suspect, is that whatever was placed into that data attribute was incorrect in the first place. – ADyson Sep 01 '23 at 08:49

0 Answers0