我有两个页面,第一个是 packagebuilder.php ,然后第二个是 hotel.php 。我必须将 packagebuilder.php 中的数据传递给 hotel.php 。 hotel.php 是酒店列表的关怀表,我希望在 packagebuilder.php中显示该列表
这是输入部分,当我将所有细节放在表单中然后单击提交按钮然后只有酒店列表部分应该刷新表中的项目列表而不是整个页面
<div>
<select id="Country" class="dropdown">
<option value="">Select</option>
...
</select>
<select id="Destination" class="dropdown">
<option value="">Select</option>
...
</select>
<input type="date" name="checkin" id="name" placeholder="Date" required/>
<input type="date" name="checkout" id="name" placeholder="Date" required/>
<input type="text" name="hotel" id="hotel" placeholder="Hotel... Optional" required/><br/><br/>
<select id="room" class="dropdown">
<option value="">Select</option>
...
</select>
<select id="adult" class="dropdown">
<option value="">Select</option>
...
</select>
<select id="child" class="dropdown">
<option value="">Select</option>
...
</select>
<select id="infant" class="dropdown">
<option value="">Select</option>
...
</select>
<select id="ratingmin" class="dropdown">
<option value="">Select</option>
...
</select>
<select id="ratingmax" class="dropdown">
<option value="">Select</option>
...
</select>
<input type="submit" id="submit" name="submit" value="Submit" class="button">
<br/><br/>
</div>
答案 0 :(得分:0)
您只需要将带有序列化表单数据的ajax请求发送到hotel.php并在页面中显示响应
$('#myForm').on('submit',function(e){
e.preventDefault();
var data = $('#myForm').serializeArray();
$.post("hotel.php", data, function(){
$( ".result" ).html( data );
});
});
答案 1 :(得分:0)
最好的方法是将酒店列表表格写在一个名为“hotel.php”的单独文件中,并在主页面(packagebuilder.php)的酒店列表部分div中包含该文件。
首先在packagebuilder.php中创建一个显示酒店列表部分的div
<div id="div-hotel-list"> </div>
还在<head>
部分添加以下脚本...
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function() {
$('#submit').on('click', function() {
var url = 'hotel.php'; // the page containing Hotel list only
$('#div-hotel-list').load(url); // the div in the main page where hotel list should be displayed.
});
});
</script>
答案 2 :(得分:0)
尝试使用此
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#submit').click(function() {
var country_id = $("select#ddlcountry option:selected").attr('value');
var dest_id = $("select#ddldest option:selected").attr('value');
var rooms_val = $("select#ddlroom option:selected").attr('value');
var adult_val = $("select#ddladult option:selected").attr('value');
var child_val = $("select#ddlchild option:selected").attr('value');
var infant_val = $("select#ddlinfant option:selected").attr('value');
var rtmin_val = $("select#rtmin option:selected").attr('value');
var rtmax_val = $("select#rtmax option:selected").attr('value');
var checkin = $("#checkin").val();
var checkin = $("#checkout").val();
var checkin = $("#hotel").val();
var datastring = {
"ddlcountry":country_id,
"ddldest":dest_id,
"checkin":checkin,
"checkout":checkout,
"hotelname":htmane,
"ddlroom": rooms_val,
"ddladult":adult_val,
"ddlchild":child_val,
"ddlinfant":infant_val,
"rtmin":rtmin_val,
"rtmax":rtmax_val,
}
$.ajax({
type: "POST",
url: "hotel.php",
data: datastring,
cache: false,
success: function(html) {
$('.result').html( html );
}
});
});
});
</script>