Datepicker始终返回相同的值 [英] Datepicker returns the same value all the time

查看:44
本文介绍了Datepicker始终返回相同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题有点难以解释,所以我做了一个简短的屏幕录制我的问题:



https ://www.youtube.com/watch?v = maXwOJRWf28



所以你可能会在视频中看到有一个列为



My problem is a little bit hard to explain, so I made a short screen recording of what my problem is:

https://www.youtube.com/watch?v=maXwOJRWf28

So as you might see in the vide there is a Column with

Day_hours       Day_minutes
   3                 45
   4                 15
   5                 45 
   2                 15





我想在特定时间段内计算小时和分钟。我的意思是,我会得到一个数字,表示该时间段内有多少小时和分钟。它适用于计算。视频中的Fx我选择日期2014-03-03 - 2014-03-04并获得15.2小时的结果。如果我然后选择日期2014-03-24 - 2014-03-28我仍然得到结果15.2小时,即使这些日期没有数据。所以不知道它,我认为我的javascript dosent得到我选择的日期,servlet只是遍历数据库中的所有列并取这些的SUM?有人可以看到它是我的javascript我需要更多的代码,还是在我的servlet中?希望你们中的一些人有时间帮助我。



最好的问候Mads



Javascript代码:





I want to calculate the hours and minutes together in the specific time period. By that I mean I would get one number with how many hours and minutes there is in the time period. It works with the calculation. Fx in the video I choose the dates 2014-03-03 - 2014-03-04 and get the result 15.2 hours. If I then choose the dates 2014-03-24 - 2014-03-28 I still get the result 15.2 hours, even if there is no data in those dates. So without knowing it, I think my javascript dosent get the dates i choose, and the servlet just go through all my columns in the database and take the SUM of these? Can someone see if it is my javascript I need some more code, or in my servlet? Hope some of you have time to help me.

Best Regards Mads

Javascript code:

<form>
        <input id="startDate" />
        <input id="endDate" />
    </form>
    <div id="startresult"></div>
    <div id="endresult"></div>
    <script>

    $(function(){
        $("#startDate").datepicker({
            dateFormat: 'yy-mm-dd',
            onSelect: function(dateText,inst){
                $('.selected-date').html(dateText);

                $.ajax({
                      url: "../getHoursSQL",
                      type: "post",
                      data: JSON,
                      success: function(data){
                          alert("success");
                          $("#startresult").html(data);

                      },
                      error:function(){
                          alert("failure");
                          $("#startresult").html('there is error while submit');
                      }  
                    });
            }
        });
    });

    $(function(){
            $("#endDate").datepicker({
                dateFormat: 'yy-mm-dd',
                onSelect: function(dateText,inst){
                    $('.selected-date').html(dateText);

                    $.ajax({
                          url: "../getHoursSQL",
                          type: "post",
                          data: JSON,
                          success: function(data){
                              alert("success");
                              $("#endresult").html(data);
                          },
                          error:function(){
                              alert("failure");
                              $("#result").html('there is error while submit');
                          }  
                        });
                }
            });
        });

</script>





Servlet代码:





Servlet code:

package WorkPackage;

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

@WebServlet("/getHoursSQL")
public class getHoursSQL extends HttpServlet{

    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    public void doPost(HttpServletRequest req, HttpServletResponse res) 
        throws ServletException, IOException{

        String connectionURL = "jdbc:mysql://localhost/NekiWork";
        Connection connection=null;

        try {

            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection(connectionURL, "root", ""); 
            String sql = "SELECT *, (Day_hours + (Day_minutes / 100)) AS Allday_hours FROM Workdata";
            PreparedStatement pst = connection.prepareStatement(sql);

            ResultSet rs = pst.executeQuery(sql);

            float Allday_hours_sum = 0;
                while (rs.next()){                                      
                    Allday_hours_sum += Float.parseFloat (rs.getString("Allday_hours")); 

                }   
                res.setContentType("text/html;charset=UTF-8");          
                res.getWriter().print(Allday_hours_sum);    

            pst.close();

        }
        catch(ClassNotFoundException e){

            System.out.println("Couldn't load database driver: " + e.getMessage());
        }
        catch(SQLException e){
            System.out.println("SQLException caught: " + e.getMessage());
        }
        catch (Exception e){
            System.out.println(e);
        }
        finally {

            try {
                if (connection != null) connection.close();
            }
            catch (SQLException ignored){
                System.out.println(ignored);
            }
        }
    }
}

推荐答案

function (){


#startDate)。datepicker({
dateFormat:' yy-mm-dd'
onSelect: function (dateText,inst){
("#startDate").datepicker({ dateFormat: 'yy-mm-dd', onSelect: function(dateText,inst){


' .selected-date')。html(dateText);
('.selected-date').html(dateText);


这篇关于Datepicker始终返回相同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆