如何在datepicker更改日期时使用ajax发布?

Leo*_*oki 5 ajax jquery datepicker

下午好

输入中的值随datepicker ui而变化.

我想在输入中的值改变时使用ajax post.

为此,我使用脚本:

<input type="text" name="date" class="datepicker" id="datepicker">

$(".datepicker").datepicker({changeYear: true});

$(".datepicker").on("change",function(){
var date=$(this).val();
$.post("test.php", {
date:date
},
function(data){$('#testdiv').html('');$('#testdiv').html(data);
});
});
Run Code Online (Sandbox Code Playgroud)

但是ajax post查询是使用旧日期执行的.

Datepicker在输入中没有时间更改值.

告诉我如何在datepicker更改字段中的日期后进行查询?

我需要:

1)datepicker更改日期;

2)查询应该与新日期一起发送.

Sak*_*vel 11

您可以在datepicker事件上触发ajax帖子:

$("#datepicker").datepicker({

    onSelect: function(date, instance) {

        $.ajax
        ({
              type: "Post",
              url: "www.example.com",
              data: "date="+date,
              success: function(result)
              {
                  //do something
              }
         });  
     }
});
Run Code Online (Sandbox Code Playgroud)

希望这有帮助 - @Codebrain