1

I have a textbox with datepicker jquery plugin. When i select a date ,post ajax call is made and i want to return some data from database and textbox should remain on top of the page so that furthur requests can also be made.

    <script>
        $(document).ready(function(){
        //create date pickers
            $("#datepicker").datepicker(
            { 
                changeMonth: true,
                changeYear: true,
                dateFormat: 'yy-mm-dd',
                onSelect: function(date)
                {
                    $.ajax({
                        type:"POST",
                        url:"seestuffs.php",
                        data:date,
                        success: function(result)
                        {
                              document.write(result);
                        }
                    });
                }
            });
        });
    </script>
    <body>
<p>Date: <input type="text" id="datepicker" name="date" /></p><br/>
    </body>

And here is my seestuffs.php

<?php 

if(isset($_POST['date']))
{
    $date = $_POST['date'];
    echo 'hello';

}


?>

But hello is not displayed on the page.Where am I going wrong!!Thanx in advance..

user2801952
  • 13
  • 1
  • 6

1 Answers1

2

document.write will create a new document if called on a document that has already loaded. This is explained in this Question: JavaScript Document.Write Replaces All Body Content When Using AJAX.

So instead you need to add the result to the document either by appending a new node or using innerHTML eg:

success: function(result) {
   $('body').append('<p>'+result+'</p>');
}
Community
  • 1
  • 1
Petra Stone
  • 109
  • 4