Skip to content

Instantly share code, notes, and snippets.

@detournemint
Created October 3, 2014 16:55
Show Gist options
  • Save detournemint/d2b0d0e8bf67c7daeb64 to your computer and use it in GitHub Desktop.
Save detournemint/d2b0d0e8bf67c7daeb64 to your computer and use it in GitHub Desktop.
Ajax Pagination using the Pagination from Will Paginate
$(document).ready(function() {
$('.datepicker').datepicker();
$(".tablesorter").tablesorter();
var submit = document.getElementById("submit-button");
submit.onclick = getCalendarAppointments;
$(".pagination").on("click", 'a', function(event){
event.preventDefault();
getCalendarAppointments($(this));
});
});
function getCalendarAppointments(arg){
event.preventDefault();
$('#calendar_appointments').empty();
$("#spinner").html('<img alt="Small-loading-spinner" src="/assets/small-loading-spinner.gif">');
var technician = $('#technician').val();
var start_date = $('#start_date').val();
var end_date = $('#end_date').val();
var office = $('#office').val();
var type = $('#type').val();
if (typeof(arg.html) == "function") {
var queryDict = {};
var parser = document.createElement('a');
parser.href = arg.attr("href");
parser.search.split("?").forEach(
function(item) {item.split("&").forEach(
function(item) {queryDict[item.split("=")[0]] = item.split("=")[1]})
}
);
var page = queryDict.page;
} else {
var page = "1";
};
var url = "/get_calendar_appointments";
$.ajax({
type: "GET",
cache: false,
url: url,
data: {
'technician': technician,
'start_date': start_date,
'end_date': end_date,
'office': office,
'type': type,
'page': page
},
statusCode: {
200: function(response) {
$('#calendar_appointments').html(response);
$('#spinner').empty();
$(".tablesorter").tablesorter();
$(".pagination").on("click", 'a', function(event){
event.preventDefault();
getCalendarAppointments($(this));
});
},
404: function() {
$('#calendar_appointments').html("Server Error, Please Contact The Development Team");
$('input[type="submit"]').removeAttr('disabled');
$('#spinner').empty();
}
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment