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):

  1. is url provided in ajax above correct?
  2. how should pass data ajax php (url: "<?php echo base_url(); ?>backend/umat/add")?

thanks :d

what have missed here:

  1. your click event outside of doc ready handler, should inside doc ready when page gets ready element should available click.
  2. 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    }); }); 

see demo here


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -