Sure. What part are you having trouble converting? Or are you just looking for someone to do the job for you?
Dec 6, 2019
10
Level 2
Coverting from jquery to javascript
Hello I have this code in jquery and I want to cover it to pure javascript cuz does not make any sense for me to use 80k liberty to just make a small task can anyone help please am very bad when it comes to js but kind of good at jquery. Jquery
<script async>
$(document).on('click', '.pagination a', function(event){
event.preventDefault();
$(".page-loader").removeClass('page-loader-hidden');
var page = $(this).attr('href').split('page=')[1];
fetch_data(page);
});
function fetch_data(page){
$.ajax({
url: '/pagination/fetch_browsergames_data?page='+page,
success: function(data){
$("#games_content").html(data);
$('html, body').animate({scrollTop : 0},1000);
var lazyLoadInstance = new LazyLoad({
elements_selector: ".lazy"
// ... more custom settings?
});
$(".page-loader").addClass('page-loader-hidden');
}
})
}
//search box
$(document).ready(function(e){
$("#searchBox").keyup(function() {
$("#show_upSearch").removeClass('d-none');
var text = $(this).val();
var textlen = $(this).val(),length;
$.ajax({
method:"GET",
url:"/search-box/browser-game",
data:{text:text},
success:function(data){
if (textlen != 0) {
$("#show_upSearch").html(data);
}else{
$("#show_upSearch").html("");
}
}
})
});
});
</script>
Level 102
Here is an example :)
function fetch_data(page){
var request = new XMLHttpRequest();
request.open('GET', '/pagination/fetch_browsergames_data?page='+page,, true);
request.onload = function() {
if (this.status >= 200 && this.status < 400) {
// Success!
var data = JSON.parse(this.response);
//redo the next part with javascript.
$("#games_content").html(data);
$('html, body').animate({scrollTop : 0},1000);
var lazyLoadInstance = new LazyLoad({
elements_selector: ".lazy"
// ... more custom settings?
});
$(".page-loader").addClass('page-loader-hidden');
}
};
request.send();
1 like
Please or to participate in this conversation.