javascript - how to do $_POST for datepicker in php/codeigniter -
first, i'm using codeigniter framework , i'm beginner in js , ajax, please bear me.
i read this question, tried follow answers.
this script (updated):
$(function() { $( "#datepicker").datepicker().click(function() { $.ajax({ type: 'post', url: "<?php echo base_url(); ?>backend/umat/add", datatype: "json", data: $('#form_daftar').serialize(), success: function(data) { console.log("done"); } }); return false; }); });
and datepicker html code:
<input type="text" id="datepicker" name="datepicker" value="<?php echo isset($umat['tanggal_lahir'])?$umat['tanggal_lahir']:""?>"/>
my questions (updated):
- is url provided in ajax above correct?
- how should pass data ajax php (
url: "<?php echo base_url(); ?>backend/umat/add"
)?
thanks :d
what have missed here:
- your click event outside of doc ready handler, should inside doc ready when page gets ready element should available click.
- you have missed closing
});
tag of click event.(does not matter though)
so try this:
$(function() { $( "#datepicker").datepicker(); $("#datepicker").click(function() { $.ajax({ type: 'post', url: "<?php echo base_url(); ?>backend/umat/add", datatype: "json", data: {frmdata : $('#form_daftar').serialize()}, // <----send way success: function(data) { console.log(data.date); // here data returned data specified url , make sure // url generating proper json structrue. // suppose there key named date holds submitted date // data.date date. } }); }); //<----you missed closing of click function. }); //<----------put before closing of doc ready handler.
although can chain this:
$(function(){ $( "#datepicker").datepicker().click(function() { //......ajax function in click here }); });
Comments
Post a Comment