[英]Ajax and jQuery call of $ajax url not working
I will try to explain it a bit better. 我会尽力解释一下。
I have REST api I'm connecting to via the URL in the ajax. 我有通过ajax中的URL连接到的REST api。 When I get that information I want to update the content within so the content is updated according to the data got from the api call.
当我获得该信息时,我想更新其中的内容,以便根据api调用获得的数据来更新内容。
<button onclick="myFunction()">LOAD</button><br /><br />
<div class="spinner bar hide">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div class="searchtable"><?php include 'hotels/hotelList.php';?></div>
<script>
function myFunction() {
$('.searchtable').addClass('hide');
$('.spinner').removeClass('hide');
$.ajax({
url: 'hotels/hotelSortBy.php?name=<?php echo $name;?>&arrival=<?php echo $arrival;?>&departure=<?php echo $departure;?>&guests=<?php echo $numberOfGuests;?>'
}).done(function() {
$('.spinner').addClass('hide');
$('.searchtable').removeClass('hide');
});
}
</script>
The issue is with your ajax call functionality 问题出在您的ajax调用功能上
you have to change your ajax call like below 您必须像下面那样更改ajax调用
$.ajax({
type: 'GET',
data: {'name':'<?php echo $name;?>','arrival':'<?php echo $arrival;?>','departure':'<?php echo $departure;?>','guests':'<?php echo $numberOfGuests;?>'},
url: 'hotels/hotelSortBy.php',
success: function (data) {
// do what ever you want to do with this response data
},
error: function (xhr) {
// do what ever you want to do when error happens
}
});
Thats the way to send GET request to a url using ajax 这就是使用ajax将GET请求发送到URL的方式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.