Skip to content
Snippets Groups Projects
Commit 3ce72d14 authored by Muhammad Rifko Favian's avatar Muhammad Rifko Favian
Browse files

fix: ajax config

parent 20d9e901
No related merge requests found
......@@ -50,18 +50,35 @@
const eventId = urlParams.get('id');
document.addEventListener("DOMContentLoaded", function(){
// Fetch user data on page load
fetch('../../router.php?eventAction=getEvent&eventId=' + eventId)
.then(response => response.json())
.then(data => {
var xhr = new XMLHttpRequest();
xhr.open('GET', '../../router.php?eventAction=getEvent&eventId=' + eventId, true);
// Set up a function to run when the request is successfully completed
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
// Parse the JSON
var data = JSON.parse(xhr.responseText);
// Log and utilize data
console.log(data);
// Populate the form fields with the data
document.querySelector('input[name="eventName"]').value = data.event_name;
document.querySelector('input[name="eventPrice"]').value = data.event_price;
document.querySelector('input[name="eventDate"]').value = data.event_date;
document.querySelector('input[name="eventLocation"]').value = data.event_location;
})
.catch(error => console.error(error));
} else {
// Handle error: log status text
console.log('Failed to fetch event:', xhr.statusText);
}
};
// Set up a function to handle any errors that may occur
xhr.onerror = function () {
console.error('Request failed:', xhr.statusText);
};
// Send the request
xhr.send();
});
const cancelButton = document.getElementById("cancelButton");
......
......@@ -31,17 +31,33 @@
<?php include '../template/footer.php'; ?>
<script>
document.addEventListener("DOMContentLoaded", function(){
// Fetch user data on page load
fetch('../../router.php?userAction=getUser')
.then(response => response.json())
.then(data => {
console.log(data);
// Populate the form fields with the data
var xhr = new XMLHttpRequest();
xhr.open('GET', '../../router.php?userAction=getUser', true);
// Set up a function to run when the request is successfully completed
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
// Parse the JSON
var data = JSON.parse(xhr.responseText);
// Log and utilize data
document.querySelector('input[name="user_name"]').value = data.user_name;
document.querySelector('input[name="user_username"]').value = data.username;
document.querySelector('input[name="user_email"]').value = data.user_email;
})
.catch(error => console.error(error));
} else {
// Handle error: log status text
console.log('Failed to fetch user:', xhr.statusText);
}
};
// Set up a function to handle any errors that may occur
xhr.onerror = function () {
console.error('Request failed:', xhr.statusText);
};
// Send the request
xhr.send();
});
const cancelButton = document.getElementById("cancelButton");
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment