[英]jQuery.ajax and not parsed via GET request
I'm trying to parse value (adults) from select option field through a GET request with the use of AJAX. 我正在尝试使用AJAX通过GET请求从选择选项字段中解析值(成人)。 I can parse the value through the url - by checking the url with the alert of the url in the jQuery function.
我可以通过url解析值-通过使用jQuery函数中的url警报来检查url。 But I can't retrieve the value within the page I do the GET request.
但是我无法在执行GET请求的页面中检索值。
jQuery.ajax jQuery.ajax
<script>
$('.roomAvailable').change(
function roomChanges(data) {
var over = '<div id="overlaysRooms">'
+ '<div id="loading"><div class="loaders"></div><div id="loadertextsearch">Vent Venligst...</div>'
+ '</div>';
$(over).appendTo('.rooms');
$('.rooms').addClass('overlaysRooms');
$.ajax({
type: 'GET',
data: {
'arrival': '<?php echo strval($_GET[' arrival ']); ?>',
'departure': '<?php echo strval($_GET['departure ']);?>',
'adults': $("#adults option:selected").val(),
'hotelId': '<?php echo strval($_GET[' hotelId ']);?>',
'room1': $("#rooms option:selected").val()
},
url: '<?php echo $baseUrl ?>/hotels/hotelRoomAvailable.php',
success: function(data) {
alert(this.url);
$('#roomsavailable').replaceWith(data);
$('#overlaysRooms').remove();
},
error: function(xhr) {}
})
});
</script>
hotelRoomAvailable.php: hotelRoomAvailable.php:
<?php
var_dump(intval($_GET['adults']));
?>
Alert value: http://example.com/hotels/hotelRoomAvailable.php?arrival=03%2F13%2F2015&departure=03%2F18%2F2015&adults=5&hotelId=375477&room1=1 警报值: http : //example.com/hotels/hotelRoomAvailable.php?arrival = 03%2F13%2F2015&departure = 03%2F18%2F2015&adults = 5&hotelId = 375477&room1 = 1
So when I check with var_dump to retrieve value of adults I get nothing. 因此,当我检查var_dump以获取成人的价值时,我什么也没得到。 Why is it the value is not parsed to the page when I see the value is parsed in the alert message from jQuery ?
当我看到jQuery的警报消息中已解析了该值时,为什么未将该值解析到该页面?
You are (almost certainly) getting the expected result back from the PHP script you are calling. 您(几乎可以肯定)从所调用的PHP脚本中获得了预期的结果。
What if you insert, just before
$('#roomsavailable').replaceWith(data);
如果在
$('#roomsavailable').replaceWith(data);
之前插入怎么办? , the linealert($('#roomsavailable').length)
?,行
alert($('#roomsavailable').length)
吗? – Quentin–昆汀
Then I get
0
@Quentin – Troels Johannesen然后我得到
0
@Quentin – Troels Johannesen
The problem is, that $('#roomsavailable')
doesn't find any element with that id, so there is nothing to replace with the data you get. 问题是,
$('#roomsavailable')
找不到具有该ID的任何元素,因此没有任何东西可以替换为您获得的数据。
You need to make sure that an element with that id exists in the document. 您需要确保文档中存在具有该ID的元素。
Please just add the _GET variables to the url. 请仅将_GET变量添加到网址中。
And remove the "type" and "data" variables completely. 并完全删除“类型”和“数据”变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.