jQuery datepicker更改日期时如何使用ajax post?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14995464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How use ajax post when datepicker change date?
提问by Leo Loki
Good afternoon
下午好
Value in input change with datepicker ui.
输入值随 datepicker ui 更改。
I want use ajax post when value in input will be change.
当输入中的值将更改时,我想使用 ajax post。
For this i use script:
为此,我使用脚本:
<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);
});
});
But ajax post query is executed with the old date.
但是ajax post查询是用旧日期执行的。
Datepicker does not have time change value in input.
日期选择器在输入中没有时间变化值。
Tell me how to do query after datepicker change the date in the field?
请告诉我如何在 datepicker 更改字段中的日期后进行查询?
Me need:
我需要:
1) datepicker change the date;
1)datepicker改变日期;
2) query should be send with new date.
2) 查询应使用新日期发送。
回答by Sakthivel
You can trigger ajax post on datepicker events:
您可以在 datepicker 事件上触发 ajax 发布:
$("#datepicker").datepicker({
onSelect: function(date, instance) {
$.ajax
({
type: "Post",
url: "www.example.com",
data: "date="+date,
success: function(result)
{
//do something
}
});
}
});
Hope this helps- @Codebrain
希望这会有所帮助-@Codebrain
回答by andri
回答by Karthik Chintala
Instead of using on(change
you have onSelect
for datepicker, which will fire when the date is changed.
而不是使用on(change
您拥有onSelect
的日期选择器,它会在日期更改时触发。
$(function(){
$('.datepicker').datepicker({
onSelect:function(dateText,instance){
alert(dateText); //Latest selected date will give the alert.
$.post("test.php", {
date:dateText // now you will get the selected date to `date` in your post
},
function(data){$('#testdiv').html('');$('#testdiv').html(data);
});
}
});
});
Hope it helps.
希望能帮助到你。
回答by Gryfith
You can use changeDate
您可以使用 changeDate
$('.datepicker').datepicker()
.on('changeDate', function(e) {
// `e` here contains the extra attributes
});
you can check here : http://bootstrap-datepicker.readthedocs.io/en/latest/events.html
你可以在这里查看:http: //bootstrap-datepicker.readthedocs.io/en/latest/events.html