E
E
Eugene2018-02-22 11:33:24
Bootstrap
Eugene, 2018-02-22 11:33:24

How to send data with ajax datetimepicker bootstrap?

I have a calendar on the page

<div class="form-group">
                    <!-- элемент input с id = datetimepicker1 -->
                    <div class="input-group" id="datetimepicker1">
                        <input type="text" class="form-control" />
                        <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </div>
                </div>


I need to send date to php file. And when choosing another date, send another date to the datatimepicker.

I climbed and found that the datetimepicker has an event that fires when the date changes -dp.change

I'm a noob in js, but I did it like this
$(function () {

    $('#datetimepicker1').datetimepicker(
        {format: 'DD.MM.YYYY', locale: 'ru'}


  );

    $('#datetimepicker1').on("dp.change", function ()
    {
        var a = $("#datetimepicker1").data("datetimepicker").getDate();
        $.ajax(
            {
                url:'index.php?r=category/viewdoc',
                data: a,
                type: 'GET',
                success: function (res) {
                    console.log(res);
                },
                error:function () {
                    alert('Error');
                }
            }
        );
    });
});


But it gives an error. Even if I write the text to the variable a. How to correctly issue ajax when changing the date?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question