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 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试