简体   繁体   English

jQuery Datepicker触发POST

[英]jQuery Datepicker to Trigger a POST

i want to use jquery UI's datepicker to trigger a POST that would then load information from the date picked on the datepicker from my database. 我想使用jquery UI的datepicker触发POST,然后从数据库中从datepicker上选择的日期加载信息。

so i guess this is a two-part question 所以我想这是一个两部分的问题

is there a way i can make it so the datepicker date, when selected, just gets passed into a POST, so someone would click on jan 1 2010 and it would automatically go to mysite.com?date=01012010 or something like that the way it is now the datepicker just updates a text box with the date, so upon clicking on jan 1 2010, the text box is populated with 01-01-2010 有没有一种方法可以使日期选择器日期(选中时)传递到POST中,因此有人单击2010年1月1日,它将自动转到mysite.com?date=01012010或类似的方式现在它是日期选择器,只是用日期更新了一个文本框,因此在单击Jan 1 2010时,该文本框将填充01-01-2010

which brings me to part 2 if there is no way to do what i asked in part 1, is there a method that triggers an event on the text box being updated, that way i could just do 如果没有办法执行我在第1部分中要求的操作,这将使我进入第2部分,是否有一种方法可以触发正在更新的文本框上的事件,所以我可以这样做

onTextUpdate{ onTextUpdate {

redirect to - mysite.com?date=$whateverIsInTextBox 重定向到-mysite.com?date=$whateverIsInTextBox

} }

or something like that 或类似的东西

please let me know if you have any solutions or ideas to do this, thanks a lot 请让我知道您是否有解决方案或想法,非常感谢

You could do something like this if you don't want to use ajax: 如果不想使用ajax,可以执行以下操作:

$("#datepicker").datepicker({

    onSelect: function(date, instance) {
            window.location = "www.example.com/?date="+date;
    }
});

And if you do: 如果您这样做:

$("#datepicker").datepicker({

    onSelect: function(date, instance) {

        $.ajax
        ({
            type: "GET",
            url: "www.example.com",
            data: "date="+date,
            success: function(result)
            {
               //do something
            }
       });  
    }
});

use the OnSelect event of the date picker 使用日期选择器的OnSelect事件

$('id').datepicker({
   onSelect: function(dateText, ins) { ... }
});

you can try other events of the datepicker control based on your requirement 您可以根据需要尝试使用datepicker控件的其他事件

There are a number of events attached to the jQuery datepicker widget; jQuery datepicker小部件附带了许多事件。 onSelect should cover point #1 above: onSelect应该涵盖上面的#1点:

$('.selector').datepicker({
   onSelect: function(dateText, inst) { ... }
});

In your case, you can use the $.GET or $.POST functions to pass the data to the server. 您可以使用$ .GET或$ .POST函数将数据传递到服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM