How to do $.getJSON when datepicker changes value?

How to do $.getJSON when datepicker changes value?

Hi

I am trying to send a ajax request to set cookies and once the cookies are set then reload the page.

I need this request to be automatically sent as soon as the user select a date from the datepicker.

I have tried the following code but it does not work.

thanks for your help :)

  1. <script>
  2. $(function() {
  3. $( '#scheduledOn' ).datepicker({
  4. showOn: "button",
  5. buttonImage: "images/calendar.gif",
  6. buttonImageOnly: true,
  7. changeMonth: true,
  8. changeYear: true,
  9. onSelect: function() { 
  10. $.getJSON("ajax/cookies_handler.php", {
  11. date: $(this).val(),
  12. action : 'ScheduledOn'
  13. },function (data) {
  14. console.log(data);
  15. if(data == 'Ok'){
  16. var delay = 500;
  17. var URL = "index.php";

  18. setTimeout(function(){ window.location = URL; }, delay);
  19. }
  20. }
  21. );
  22. }
  23. });

  24. });
  25. </script>