You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

45 lines
1.1 KiB

function getFormData($form, pageNum) {
var unindexed_array = $form.serializeArray();
var indexed_array = {};
$.map(unindexed_array, function (n, i) {
indexed_array[n['name']] = n['value'];
});
indexed_array["page"] = pageNum || "";
return indexed_array;
}
function modUrl($form, postfix) {
let curLoc = '?' + $form.serialize() + (postfix || "");
try {
history.replaceState($form.serialize(), null, curLoc);
} catch (e) {
console.log("Error!");
}
}
function sendData(url, $form, pageNum) {
function updateResults(html) {
$container.html(html);
}
const $container = $('#projectsBlock');
$.ajax({
url: url,
type: "POST",
dataType: 'html',
data: getFormData($form, pageNum),
beforeSend: function (xhr) {
xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken'));
},
success: updateResults,
error: (data) => console.log("Error", data)
});
}
function sendFilterData(url) {
const $form = $('#filter-form');
sendData('/projects/', $form);
modUrl($form);
return false;
}