Created
April 23, 2024 19:45
-
-
Save rodrigophpweb/c2f948a0a90fd0d8ba75c74785788ee1 to your computer and use it in GitHub Desktop.
Ajax request code to list the activities of the units related to the event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const url = wp.ajaxurl; // Sua URL de solicitação | |
const urlComParametros = `${url}?action=listActivities&slug=${slug}&level=${level}&school=${school}×tamp=${new Date().getTime()}`; | |
const updateActivities = (slug, level, school) => { | |
fetch(urlComParametros, { | |
method: 'POST', | |
credentials: 'same-origin', | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'Cache-Control': 'no-cache', | |
}, | |
body: new URLSearchParams({ | |
action: 'listActivities', | |
slug: slug, | |
level: level, | |
school: school, | |
}), | |
}) | |
.then((response) => response.text()) | |
.then((data) => { | |
document.querySelector('#listActivities').innerHTML = data; | |
sortPostsByDateTime(); | |
}) | |
.catch((error) => { | |
console.log(error); | |
}); | |
}; | |
const slug = document.location.pathname.split('/')[2]; | |
const level = document.querySelector('article.events').getAttribute('class').split(' ')[0]; | |
const schoolFilter = document.querySelector('#filterSchool'); | |
if (schoolFilter) { | |
schoolFilter.addEventListener('change', function () { | |
const selectedSchool = this.value; | |
updateActivities(slug, level, selectedSchool); | |
}); | |
} | |
sortPostsByDateTime(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment