jQuery Datepicker to Trigger a POST

两盒软妹~` 提交于 2019-12-08 11:58:12

问题


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.

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

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

onTextUpdate{

redirect to - 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


回答1:


You could do something like this if you don't want to use 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
            }
       });  
    }
});



回答2:


use the OnSelect event of the date picker

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

you can try other events of the datepicker control based on your requirement




回答3:


There are a number of events attached to the jQuery datepicker widget; onSelect should cover point #1 above:

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

In your case, you can use the $.GET or $.POST functions to pass the data to the server.



来源:https://stackoverflow.com/questions/1014554/jquery-datepicker-to-trigger-a-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!