0

In my application I want to show a datepicker (jquery) where only some dates are enabled. I get those dates from MySql DB. How can I send these paramemeters to datepicker through ajax?

<input type="text" name="t_Date" id="t_Date">
<script>
    $("#t_Date").datepicker({ 
       datesEnabled : ajax_getDates.php // Here what I need help 
    });
</script>

I don't know whether the getDates methode exists or not.

5
  • 2
    Where is your code? And what have you tried so far? Commented Dec 22, 2015 at 7:49
  • <input type="text" name="t_Date" id="t_Date"> <script>$("#t_Date").datepicker({ datesEnabled : ajax_getDates.php // Here what I need help })</script>. Dont know whether the getDates methode exists or not. Commented Dec 22, 2015 at 7:51
  • Please add your code, what have tried yet Commented Dec 22, 2015 at 7:53
  • please add your code in description instead of comment so that it is easy to read and so that it is useful to everyone. Commented Dec 22, 2015 at 7:55
  • Ok. I will paste the code to my question Commented Dec 22, 2015 at 7:56

1 Answer 1

1

Do an ajax request and create the date picker on success callback:

<input type="text" name="t_Date" id="t_Date">
<script type="text/javascript">

    $(document).ready(function() {

        $.post('ajax_getDates.php', {}, function(data){
            $("#t_Date").datepicker({ datesEnabled : data.datesEnabled });
        }, 'json');

    });

</script>

The ajax_getDates.php file should look like:

<?php

    $datesEnabled = array('date1', 'date2', 'date3');
    echo json_encode('datesEnabled' => $datesEnabled);
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. Other than document.ready function1, can I call 1datesEnabled : data.datesEnabled on other events? like button onClick?
you can do it inside the callback.. you can do whatever you like with that variable
Oh yes... I got now. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.