dquv73115 2017-09-01 13:27
浏览 305

从DateTimePicker Bootstrap获取值

How do i get the value of a calender from my ajax and send it to a php script. I've tried most of the other threads about this but nothing has worked.

This is my PHP script which spawns the picker:

$output_string .="<td id=\"start$count\">
";
$output_string .="<div class='input-group date'>
";
$output_string .="<input type='text' class=\"form-control\" id='datetimepicker$count'>
";
$output_string .="<span class=\"input-group-addon\">
";
$output_string .="<span class=\"glyphicon glyphicon-calendar\"></span>
";
$output_string .="</span>
";
$output_string .="</div>
";
$output_string .="</td>
";

Here is the AJAX i'm using to start off another PHP script:

<script type="text/javascript" language="javascript">
        $("#run1").click(function(){
        var filename = $("#filename1").text();
        var start_time = $("#datetimepicker1").datetimepicker("getDate");
            $.ajax({
                url: "launch.php",
                type:"POST",
                data: {"value1": filename, "value2":start_time},
                dataType: "json",
                success: function(responce){
                    $("#output").html(responce);
                    } // End of success function of ajax form
                }); // End of ajax call
            });
</script>

Edit:

I use loops to generate a table. In the table are datetimepickers. The PHP also generates the AJAX which send the value to launch.php. But for some reason the value of the datetimepicker is either nothing or "undefined".

Full PHP script:

<?php

include_once "connectdb.php";

$tbquery = "select * from case_in order by created_time DESC";
$results = mysqli_query($con, $tbquery);
    $output_string ="<table id=\"table\" class=\"table table-striped\"
";
    $output_string .="<thead>
";
    $output_string .="<tr>
";
    $output_string .="<th>File Name</th>
";
    $output_string .="<th>Created</th>
";
    $output_string .="<th>Start Time</th>
";
    $output_string .="<th></th>
";
    $output_string .="</tr>
";
    $output_string .="</thead>
";
    $output_string .="<tbody>
";
    $output_string .="<tr>
";
    $count = 0;
foreach ($results as $table) {
    $output_string .="<tr>
";
    $output_string .="<td id=\"filename$count\">$table[file_name]</td>
";
    $output_string .="<td id=\"created$count\">$table[created_time]</td>
";
    $output_string .="<td id=\"start$count\">
";
    $output_string .="<div class='input-group date'>
";
    $output_string .="<input type='text' class=\"form-control\" id='datetimepicker$count'>
";
    $output_string .="<span class=\"input-group-addon\">
";
    $output_string .="<span class=\"glyphicon glyphicon-calendar\"></span>
";
    $output_string .="</span>
";
    $output_string .="</div>
";
    $output_string .="</td>
";
    $output_string .="<td><button type=\"button\" class=\"btn\" id=\"run$count\">Run Job</button>
";
    $output_string .="</tr>
";
    $count++;
    }
    $output_string .="</tr>
";
    $output_string .="</tr>
";
    $output_string .="</tbody>
";
    $output_string .="</table>
";
    $output_string .="<br>";

$n = 0;
while ($n < $count) {
    $output_string .="<script type=\"text/javascript\" language=\"javascript\">
";
    $output_string .="$(\"#run$n\").click(function(){
";
    $output_string .="var filename = $(\"#filename$n\").text();
";
    $output_string .="var start_time = $(\"#datetimepicker$n\").val;
";
    $output_string .="$.ajax({
";
    $output_string .="url: \"launch.php\",
";
    $output_string .="type:\"POST\",
";
    $output_string .="data: {\"value1\": filename, \"value2\":start_time},
";
    $output_string .="dataType: \"json\",
";
    $output_string .="success: function(responce){
";
    $output_string .="$(\"#output\").html(responce);
";
    $output_string .="} // End of success function of ajax form
";
    $output_string .="}); // End of ajax call
";
    $output_string .="});
"; 
    $output_string .="</script>
";
    $output_string .="<script type=\"text/javascript\">
";
    $output_string .="$(document).ready(function() {
";
    $output_string .="$('#datetimepicker$n').datetimepicker({
";
    $output_string .="defaultDate:new Date()
";
    $output_string .="});
";
    $output_string .="});
";
    $output_string .="</script>
";
    $n++;
    }

echo json_encode($output_string);

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧