jQuery将数据发布到div $(函数(){ $(“#datepicker”).datepicker($.extend({ 输入:对, altField:“.alternate”, 格式:“年月日”, minDate:0, 第一天:1, onSelect:函数(日期文本,实例){ $.post(“index.php”,{date:dateText}, 功能(数据){ $('#txtHint').html(''); $('#txtHint').html(数据); }); } }, )); });
我试图在DIV#txtHint中显示datepicker post数据。它可以工作,但它会将整个页面的html发布到此分区。我只希望帖子信息显示在jQuery将数据发布到div $(函数(){ $(“#datepicker”).datepicker($.extend({ 输入:对, altField:“.alternate”, 格式:“年月日”, minDate:0, 第一天:1, onSelect:函数(日期文本,实例){ $.post(“index.php”,{date:dateText}, 功能(数据){ $('#txtHint').html(''); $('#txtHint').html(数据); }); } }, )); });,php,jquery,Php,Jquery,我试图在DIV#txtHint中显示datepicker post数据。它可以工作,但它会将整个页面的html发布到此分区。我只希望帖子信息显示在 下面是index.php: <?php if(isset($_POST['date'])) { $date = strtotime($_POST['date']); $day = strtolower(date("D", $date)); } ?> <script> $(function() { $(
下面是index.php:
<?php
if(isset($_POST['date'])) {
$date = strtotime($_POST['date']);
$day = strtolower(date("D", $date));
}
?>
<script>
$(function() {
$( "#datepicker" ).datepicker($.extend({
constrainInput: true,
altField: ".alternate",
altFormat: "yy-mm-dd",
minDate: 0,
firstDay: 1,
onSelect:function(dateText,instance) {
$.post("index.php", { date:dateText },
function(data) {
$('#txtHint').html('');
$('#txtHint').html(data);
});
}
},
));
});
</script>
形式
$(函数(){
$(“#datepicker”).datepicker($.extend({
输入:对,
altField:“.alternate”,
格式:“年月日”,
minDate:0,
第一天:1,
onSelect:函数(日期文本,实例){
$.post(“index.php”,{date:dateText},
功能(数据){
var obj=$(数据);
$(“#txtHint”).html(obj.find(“didHint”).html());
});
}
}
));
});
首先选择日期
提交
我特别希望它是在一页。不为post数据调用外部脚本。
任何人都可以建议?更改
index.php
,使其在响应AJAX请求后退出,而不打印完整的HTML文件
<?php
$today = strtotime(date("d-m-Y"));
$now = strtotime(date("H:i"));
$before = "-".$settings['close_before']." hours";
if(isset($_POST['date'])) {
$date = strtotime($_POST['date']);
$day = strtolower(date("D", $date));
// THIS HERE SHOULD BE RETURNED TO TXTHINT DIV BELOW IN FORM
echo "<select name=\"time\" class=\"form-control\" disabled>";
echo "<option value=\"\">".$day."</option>";
echo "</select>";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>form</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="js/jquery.ui.datepicker-da.js"></script>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<script>
$(function() {
$( "#datepicker" ).datepicker($.extend({
constrainInput: true,
altField: ".alternate",
altFormat: "yy-mm-dd",
minDate: 0,
firstDay: 1,
onSelect:function(dateText,instance) {
$.post("index.php", { date:dateText },
function(data) {
var obj = $(data);
$("#txtHint").html(obj.find("didHint").html());
});
}
}
));
});
</script>
</head>
<body>
<form role="form" method="post" action="index.php">
<div class="box-body">
<div class="form-group">
<div class="row">
<div class="col-sm-4">
<div class="input-group">
<span class="input-group-addon text-bold uppercase"><i class="fa fa-calendar"></i> <small><i class="fa fa-asterisk text-red"></i></small></span>
<input id="datepicker" type="text" class="form-control date">
<input name="date" class="alternate" type="hidden">
</div>
</div>
<div class="col-sm-4">
<div class="input-group">
<span class="input-group-addon text-bold uppercase" style="border: none !important;"><i class="fa fa-clock-o"></i> <small><i class="fa fa-asterisk text-red"></i></small></span>
<!-- HERE IS WHERE POSTED SELECT SHOULD APPEAR -->
<div id="txtHint">
<select name="time" class="form-control" disabled>
<option value="" selected disabled>Select date first</option>
</select>
</div>
</div>
</div>
</div>
</div>
<div class="form-group">
<button type="submit" name="goforit" class="btn btn-success pull-right text-bold" style="text-transform: uppercase;">submit</button>
</div>
</div>
</form>
</body>
</html>
我认为您需要显示index.php
返回的内容,并解释您希望放入#txtHint
的部分。更改index.php
以便在打印
后调用exit()
。这只是436行文件的一部分。我只想让你看看我挣扎的部分。还有更多。我只需要返回txtHint div。你已经完成了:)谢谢兄弟!退出();实际上起了作用。就这么简单。再次感谢这篇文章的另一个问题-当我选择星期四时,它不会发布。。只有星期四。其他日子工作正常。
<?php
$today = strtotime(date("d-m-Y"));
$now = strtotime(date("H:i"));
$before = "-".$settings['close_before']." hours";
if(isset($_POST['date'])) {
$date = strtotime($_POST['date']);
$day = strtolower(date("D", $date));
// THIS HERE SHOULD BE RETURNED TO TXTHINT DIV BELOW IN FORM
echo "<select name=\"time\" class=\"form-control\" disabled>";
echo "<option value=\"\">".$day."</option>";
echo "</select>";
exit(); // <<=== Add this
}
?>