user3721305
user3721305

Reputation: 89

How to Echo jQuery AJAX POST value of date in dialog box

I am trying to echo the POST date value in a dialog box from the jQuery Datepicker from ajax. But its not working.

This is my jquery.

$( "#datepicker" ).datepicker({
dateFormat: 'dd-mm-yy',                     
onSelect: function(date) {
    $.ajax({
        type:"POST",
        url:"mypage.php",                           
        data : { date : date },
        success : function() {                                                          
                alert(date);                                    
                var dialog = $("#dialog").dialog({ autoOpen: false });
                $('#dialog123').dialog({                           
                   modal: true                      
                });
        }
    });
}

});

Here i am getting clicked date value in alert.
This is my dialog.

<div id="dialog123" style="display:none;">                              
      <?php
        echo $_POST['date'];            
      ?>
</div>

Upvotes: 1

Views: 683

Answers (2)

UserProg
UserProg

Reputation: 639

I am assuming you want to get the posted date on mypage.php. Not really sure if your ajax called is on the same page but put them in anypage.php

So in anypage.php

$( "#datepicker" ).datepicker({
    dateFormat: 'dd-mm-yy',                     
        onSelect: function(date) {
                    $.ajax({
                        type:"POST",
                        url:"mypage.php",                           
                        data : { date : date },
                        success : function(returned_data) {     
                            // stick the returned data/html where ever you like                                                     
                            alert(returned_data);
                       }
                     });
        }
  });

Then you can access the date in the mypage.php containing this code

<?php
    echo $_POST['date'];
    return;
?>

this should alert the date posted. Hope this could give you some idea.

Upvotes: 0

Mrk Fldig
Mrk Fldig

Reputation: 4486

You need to return whatever your looking from from mypage.php:

$( "#datepicker" ).datepicker({
dateFormat: 'dd-mm-yy',                     
onSelect: function(date) {
    $.ajax({
        type:"POST",
        url:"mypage.php",                           
        data : { date : date },
        success : function(returned_data) {     
            // stick the returned data/html where ever you like                                                     

        }
    });
}

Upvotes: 1

Related Questions