我正在尝试将2个ajax调用数据添加到表单中,选择第二个日期选择器,范围为datepicker系统。我可以在合适的时间发出js警报但我无法调用2个ajax请求。
我的表格有两个空的" readonly"插入字段,我希望它们包含2个ajax调用的结果。 "存款"和"价格"。
这两个php文件都会调用正确的信息,所以我需要一些帮助才能将这些信息输入到表单中。感谢。
html页面是;
<body>
From date:<br>
<input type="text" id="from" name="from" /><br>
To date:<br>
<input type="text" id="to" name="to" /><br>
Nights:<br>
<input type="text" id="nights" name="nights" readonly /><br>
Deposit:<br>
<input type="text" id="deposit" name="deposit" readonly /><br>
Price:<br>
<input type="text" id="price" name="price" readonly />
<script type='text/javascript'>
$(function() {
function datepicked() {
var fromDate = $('#from').datepicker('getDate');
var toDate = $('#to').datepicker('getDate');
if (fromDate && toDate) {
var difference_msec = toDate.getTime() - fromDate.getTime();
var difference_days = difference_msec / 86400000;
$("#nights").val(Math.ceil(difference_days));
$("#nightsh").val(Math.ceil(difference_days));
}
}
$('#from').datepicker({
numberOfMonths: 2,
firstDay: 1,
dateFormat: 'DD dd-mm-yy',
minDate: '+1D',
maxDate: '+2Y',
onSelect: function(dateStr) {
var d1 = $(this).datepicker("getDate");
d1.setDate(d1.getDate() + 0); // change to + 1 if necessary
var d2 = $(this).datepicker("getDate");
d2.setDate(d2.getDate() + 30); // change to + 29 if necessary
$("#to").datepicker("setDate", null);
$("#to").datepicker("option", "minDate", d1);
$("#to").datepicker("option", "maxDate", d2);
datepicked();
}
});
$('#to').datepicker({
numberOfMonths: 2,
firstDay: 1,
dateFormat: 'DD dd-mm-yy',
minDate: '0',
maxDate: '+2Y',
onSelect:
function(dateStr) {
alert("I am an alert box!");
datepicked()
}
});
});
</script>
</body>
2个php文件是。
price_chk.php
<?
$enqfdate ="2015-03-12";
$enqtdate ="2015-09-12";
include_once "../db_conn.php";
$query = "SELECT SUM(day_rate) FROM rates2 WHERE date BETWEEN '$enqfdate' AND '$enqtdate' - INTERVAL 1 DAY";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
$price = $row['SUM(day_rate)'];
echo "Price: €".$price."<br />";
}
?>
和
deposit_chk.php
<?
$price_id ="2";
include_once "../db_conn.php";
$query=("SELECT * FROM base_prices WHERE price_id=".$price_id."");
$results = mysql_query($query);
while ($row = mysql_fetch_array($results)) {
echo $row['price_desc'] . " - " . $row['price_amount'];
echo "<br>";
}
?>