如何从我的ajax获取日历的值并将其发送到php脚本。我已经尝试了大部分其他线程,但没有任何效果。
这是我的PHP脚本,它产生了选择器:
$output_string .="<td id=\"start$count\">\n";
$output_string .="<div class='input-group date'>\n";
$output_string .="<input type='text' class=\"form-control\" id='datetimepicker$count'>\n";
$output_string .="<span class=\"input-group-addon\">\n";
$output_string .="<span class=\"glyphicon glyphicon-calendar\"></span>\n";
$output_string .="</span>\n";
$output_string .="</div>\n";
$output_string .="</td>\n";
以下是用于启动另一个PHP脚本的AJAX:
<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>
编辑:
我使用循环来生成表格。表中有datetimepickers。 PHP还生成AJAX,将值发送到launch.php。但由于某种原因,datetimepicker的值无关紧要,或者&#34;未定义&#34;。
完整的PHP脚本:
<?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\"\n";
$output_string .="<thead>\n";
$output_string .="<tr>\n";
$output_string .="<th>File Name</th>\n";
$output_string .="<th>Created</th>\n";
$output_string .="<th>Start Time</th>\n";
$output_string .="<th></th>\n";
$output_string .="</tr>\n";
$output_string .="</thead>\n";
$output_string .="<tbody>\n";
$output_string .="<tr>\n";
$count = 0;
foreach ($results as $table) {
$output_string .="<tr>\n";
$output_string .="<td id=\"filename$count\">$table[file_name]</td>\n";
$output_string .="<td id=\"created$count\">$table[created_time]</td>\n";
$output_string .="<td id=\"start$count\">\n";
$output_string .="<div class='input-group date'>\n";
$output_string .="<input type='text' class=\"form-control\" id='datetimepicker$count'>\n";
$output_string .="<span class=\"input-group-addon\">\n";
$output_string .="<span class=\"glyphicon glyphicon-calendar\"></span>\n";
$output_string .="</span>\n";
$output_string .="</div>\n";
$output_string .="</td>\n";
$output_string .="<td><button type=\"button\" class=\"btn\" id=\"run$count\">Run Job</button>\n";
$output_string .="</tr>\n";
$count++;
}
$output_string .="</tr>\n";
$output_string .="</tr>\n";
$output_string .="</tbody>\n";
$output_string .="</table>\n";
$output_string .="<br>";
$n = 0;
while ($n < $count) {
$output_string .="<script type=\"text/javascript\" language=\"javascript\">\n";
$output_string .="$(\"#run$n\").click(function(){\n";
$output_string .="var filename = $(\"#filename$n\").text();\n";
$output_string .="var start_time = $(\"#datetimepicker$n\").val;\n";
$output_string .="$.ajax({\n";
$output_string .="url: \"launch.php\",\n";
$output_string .="type:\"POST\",\n";
$output_string .="data: {\"value1\": filename, \"value2\":start_time},\n";
$output_string .="dataType: \"json\",\n";
$output_string .="success: function(responce){\n";
$output_string .="$(\"#output\").html(responce);\n";
$output_string .="} // End of success function of ajax form\n";
$output_string .="}); // End of ajax call\n";
$output_string .="});\n";
$output_string .="</script>\n";
$output_string .="<script type=\"text/javascript\">\n";
$output_string .="$(document).ready(function() {\n";
$output_string .="$('#datetimepicker$n').datetimepicker({\n";
$output_string .="defaultDate:new Date()\n";
$output_string .="});\n";
$output_string .="});\n";
$output_string .="</script>\n";
$n++;
}
echo json_encode($output_string);
?>