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; }