简体   繁体   English

在页面加载时将jquery datepicker数据发送到php

[英]Send jquery datepicker data to php on page load

I am using jquery datepicker. 我正在使用jquery datepicker。

<form action="" method="get" name="date">
    <br />
    Start Date :<input type="text" name="sdate" id="sdate" />
    End Date : <input type="text" name="edate" id="edate" />
</form>

I am setting a default date as soon as the page loads. 页面加载后,我将设置默认日期。 And this date should be sent to php. 这个日期应该发送到php。 But I am not able to do this without the help of submit button in the above form. 但是,如果没有上述表格中的“提交”按钮的帮助,我将无法做到这一点。 How do I do this without the help of submit button? 没有提交按钮的帮助我该怎么办? I am aware I need to use onClose option. 我知道我需要使用onClose选项。 But what should I write inside it so that the data is sent to PHP? 但是我应该在里面写些什么以便将数据发送到PHP?

Here is the JS- 这是JS-

$("#sdate").datepicker({
    "dateFormat" : "yy-mm-dd",
    "onClose": ???
});
$("#edate").datepicker({
    "dateFormat" : "yy-mm-dd",
    "onClose": ???
});
$("#edate").datepicker("setDate","+0");

$("#sdate").datepicker("setDate","-7");

If your datepicker is part of a form, you can do this... 如果您的日期选择器是表单的一部分,则可以执行此操作...

onSelect: function (dateText, inst) {
 $(this).parent('form').submit();
        }

That will submit the parent form. 那将提交父母表格。

More info here.... 更多信息在这里。

http://mikemurko.com/general/jquery-ui-datepicker-form-submission-onselect/ http://mikemurko.com/general/jquery-ui-datepicker-form-submission-onselect/

More help here....almost same question... 更多帮助....几乎相同的问题...

jQuery Datepicker to Trigger a POST jQuery Datepicker触发POST

You should provide a function that takes the date and make an Ajax call or if you want to send the two dates at the same time you should store both in variables and then make the Ajax call when the second close. 您应该提供一个获取日期并进行Ajax调用的函数,或者如果您想同时发送两个日期,则应将两个日期都存储在变量中,然后在第二次关闭时进行Ajax调用。

$("#sdate").datepicker({
   "dateFormat" : "yy-mm-dd",
   "onClose": function(date, obj){
        jQuery.post('URL', {sDate: date}, function(data, textStatus, xhr) {
             //If there is success
        });
   }
});
$("#edate").datepicker({
   "dateFormat" : "yy-mm-dd",
   "onClose": function(date, obj){
        jQuery.post('URL', {eDate: date}, function(data, textStatus, xhr) {
             //If there is success
        });
   }
});

$("#edate").datepicker("setDate","+0");
$("#sdate").datepicker("setDate","-7");

Hi you can use an AJAX call in the close function 嗨,您可以在关闭功能中使用AJAX调用

onClose: function() {
        //do ajax call here 
$.ajax({
      url: "test.php",
      type: "post",
      data: values,
      success: function(){
          alert("success");

      },
      error:function(){
          alert("failure");

      }   
    }); 
      }

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

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