I want to show/hide the boostrap spinner in div #loading before and after loading more data in the ajax infinite scroll shown below. The ajax loads data perfectly well but the spinner does not show when scrolled to the point to trigger ajax. Pls help. Helping with some code example will be great.
<div class="p-3 text-center" id="loading" style="display: none" >
<button class="btn btn-danger" type="button" disabled>
<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true">Loading more items...</span>
</button>
</div>
<script type="text/javascript">
let in_ajax = false;
var flag = 20;
$(window).scroll(function() { //scroll function
if (!in_ajax) {
if ($(window).scrollTop() >= $('#result').height() - $(window).height()) {
in_ajax = true;
$.ajax({
type: 'POST',
url: 'get_results.php', //get result page
data: {
'offset': flag,
'limit': 10
},
beforeSend: function() {
$("#loading").show(); //to show spinner before ajax sends data
},
success: function(data) {
$('#result').append(data);
flag += 10; //add 10 to last offset value after callback
in_ajax = false;
},
complete: function() {
$("#loading").hide(); //to hide spinner after ajax call
}
}); //close ajax
}
}
});
</script>
Related
I recently moved from bootstrap3 to bootstrap5. Select2 in modal stopped working. I know there has been known issue in this which was resolved using
$.fn.modal.Constructor.prototype.enforceFocus = function() {}
Or using dropdownParent option for the select 2 to bind to the modal. But this didn't work for me.
So I am loading content (including modal) via ajax and populate Select2 inside it. When I click the link first time, select2 is invisible altogether. I close the modal and click the link again, it works fine the second time. I tried dame removing tabindex as well as tabindex='false'.
Clicking first time:
closed the modal and click the second time:
What am I missing here.
my Ajax code is :
HTML: <a href='url-to-controller-returning view' class='modal-remote'>Add</a>
$(document).on('click', '.modal-remote', function (e) {
e.preventDefault();
var $modalRemote = $('#modal-remote'),
url = $(this).attr('href');
$.ajax({
url: url,
beforeSend: function (data) {
if (!$modalRemote.length) $modalRemote = $('<div class="modal fade" id="modal-remote" aria-hidden="true"><div class="modal-dialog ' + modalClass + '"><div class="modal-content"></div></div></div>');
$modalRemote.find('.modal-content').html('<div class="modal-header"><h5 id="remoteModalLabel">Loading...</h5><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button></div><div class="modal-body"><div class="modal-remote-indicator"></div></div>');
$modalRemote.modal('show');
},
success: function (data) {
$.fn.modal.Constructor.prototype._enforceFocus = function() {};
var $dom = $(document.createElement('html'));
$dom[0].innerHTML = data;
$dom.find('link').remove();
$modalRemote.find('.modal-header > h5').html($dom.find('title').text());
$modalRemote.find('.modal-body').html($dom.html());
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$modalRemote.find('.modal-header > h5').html('Error');
$modalRemote.find('.modal-body').html(XMLHttpRequest.responseText);
}
});
});
I am trying to render html button inside popover and on that button's click I want to call a javascript function but through LAPTOP'S TRACKPAD that button onclick function is not firing.
<button class="seat seat-available" id="GEOJFK_32B" type="button"> </button>
<script type="text/javascript">
$('button.seat-available').click(seat_avail_click_jquery);
var lastObjPop;
function seat_avail_click_jquery() {
var obj = $(this);
if (lastObjPop != null)
lastObjPop.popover('dispose');
lastObjPop = obj;
var popupHtml = '<div class="seat-characteristics-popup ' + Math.random() + '"><div class="row"><div class="col-md-12"><h3 class="pax-name">Test User</h3></div></div>\
<div class="row"><div class="col-md-6"><h3>20044<span class="seat-type">Free</span></h3></div><div class="col-md-6 text-right"><h3>$ 0</h3></div></div>\
<div class="row"><div class="col-md-12"><button onclick="select_seat(\'DXBLHR\',\'1\',\'123\')" class="btn primary-btn select-seat">Choose</button></div></div></div>';
obj.popover({ 'html': true, content: popupHtml, animation: true, 'trigger': 'popover' });
obj.popover('show');
}
function select_seat(seg, paxid, id) {
console.log('here it is not coming.');
}
</script>
After digging and researching a lot, I realized that adding "sanitize" will do the job.
obj.popover({ 'html': true, content: popupHtml, animation: true, 'trigger': 'popover',
sanitize: false //here is the magic.
});
I'm using ons-carousel to show some images fetched from network using ajax. But the problem is, It's not showing images. but the images and carousel-items are present in the html when I see it in chrome developer tools.
And I can see the ons-carousel-item visibility is hidden in css. When I make a static ons-carousel which is not loading images from ajax but in the same manner using ng-repeat, the carousel is working fine. Here is my code.
HTML
<ons-page controller="hotelDetails">
<div ng-init="getHotel()">
<ons-carousel swipeable overscrollable auto-scroll fullscreen var="carousel" noslidingmenu>
<ons-carousel-item style="background-color: gray;" ng-repeat="thumb in images" style="visibility: visible">
<img src="{{thumb}}" style="width: 100%"/>
</ons-carousel-item>
<ons-carousel-cover><div class="cover-label">Swipe left or right</div></ons-carousel-cover>
</ons-carousel>
</div>
</ons-page>
AngularJS
module.controller('hotelDetails', function($scope){
var page = $scope.ons.navigator.getCurrentPage();
$scope.id = page.options.id;
$scope.title = page.options.title;
$scope.getHotel = function(){
console.log('Loading data');
$.ajax({
url: "http://domain.com/api/hotels/hoteldetails",
dataType: "jsonp",
data: {
id: $scope.id
},
success: function(data){
console.log('Success');
$scope.$apply(function(){
$scope.images = data.images;
});
},
error: function(error){
console.log(error);
}
});
}
});
here is a screenshot of running app.
i have my index.php to load another page (playing.php) and refresh the contents of that loaded page. It does its job for a while and then the page goes blank,then returns back with page content.Not sure what is going on with the code heres the link :mobile website
Please right click for the source code
(function($){
$(document).ready(function()
{
$.ajaxSetup(
{
cache: false,
beforeSend: function() {
$('#content').hide();
$('#loading').show();
},
complete: function() {
$('#loading').hide();
$('#content').show();
},
success: function() {
$('#loading').hide();
$('#content').show();
}
});
var $container = $("#content");
$container.load("playing.php");
var refreshId = setInterval(function()
{
$container.load('playing.php');
}, 40000);
});})(jQuery);
`
and to call the contents
<div id="wrapper">
<div id="content"></div>
<img src="images/loading.gif" id="loading" alt="loading" style="display:none;" />
`
Im trying to update dynamic values to the marquee by using ajax time to time.
Im using following plugin for this
http://remysharp.com/2008/09/10/the-silky-smooth-marquee/
Although the data is actually getting updated it does not get updated into the marquee while scrolling. If I refresh the browser it gets the updated value, that means the ajax update is working fine. What am I doing wrong here?, I need to get the update without stopping the ongoing scrolling of data and without refreshing the browser.
$(document).ready(function() {
$(".scroll").marquee();
var i = setInterval(function (){
$.ajax({
type : "GET",
url : 'http://Data.xhtml',
dataType : "json",
success: function(data) {
var values = '';
$.each(data, function(i, item) {
values += '<span class=\'up\'>
<span class=\'quote\'>'+data[i].Data+'</span></span>';
$(".scroll").marquee(values);
});
},
return false;
}, 4000);
});
});
<div class="scroll">
<span class="up">
<span class="quote">default value</span>
</span>
</div>
$(document).ready(function(){
$(".scroll").marquee();
var refreshId = setInterval(function()
{
$.ajax({
type : "GET",
url : 'http://Data.xhtml',
dataType : "json",
success: function(data) {
data=eval(data);
$.each(data.Data, function(i) {
$(".quote").append('<span class=\'up\'><span class=\'quote\'>'+data.Data[i]+'</span> </span>');
});
}
});
}, 3000);
});
<div class="scroll">
<span class="up">
<span class="quote">default value</span>
</span>