Skip to content
Snippets Groups Projects
Commit 6f067811 authored by Afnan  Ramadhan's avatar Afnan Ramadhan
Browse files

feat: bisa subcribe unsubs dari soap

parent 0a332fb0
Branches test/image-render
No related merge requests found
...@@ -32,7 +32,7 @@ const loadpage = (id) => { ...@@ -32,7 +32,7 @@ const loadpage = (id) => {
<h2 id="author">${content.author}</h2> <h2 id="author">${content.author}</h2>
<h4 id="totSubs">${content.total_subscriber} Subscribers</h4> <h4 id="totSubs">${content.total_subscriber} Subscribers</h4>
</div> </div>
<button type="button" class=${subs} id="subscribe" onclick=subscribe(${id},${uuid})>${subs}</button> <button type="button" class=${subs} id="subscribe" onclick=subscribe(${id},'${uuid}')>${subs}</button>
</div> </div>
<div class="factcontainer"> <div class="factcontainer">
<img src="${content.path_photo}" alt="" id="imageContent"> <img src="${content.path_photo}" alt="" id="imageContent">
...@@ -49,32 +49,66 @@ const loadpage = (id) => { ...@@ -49,32 +49,66 @@ const loadpage = (id) => {
} }
const subscribe = (id,uuid) => { const subscribe = (idContent,uuid) => {
console.log(uuid); console.log(uuid);
console.log(id); console.log(idContent);
const subscribeButton = document.getElementById('subscribe'); const subscribeButton = document.getElementById('subscribe');
let idUser = "";
const cookie = getCookie('user');
if (cookie !== null) {
try {
const jsonData = JSON.parse(cookie);
idUser = jsonData[0].id;
console.log('ID Value:', idUser);
} catch (error) {
console.error('Error parsing JSON:', error);
}
} else {
console.log('Cookie not found');
}
if(subscribeButton.innerHTML == "Subscribe"){ if(subscribeButton.innerHTML == "Subscribe"){
subscribeButton.innerHTML = "Unsubscribe"; subscribeButton.innerHTML = "Unsubscribe";
// xhttp = new XMLHttpRequest(); console.log("unsub");
// xhttp.onreadystatechange = function() { xhttp = new XMLHttpRequest();
// if (this.readyState === 4){ xhttp.onreadystatechange = function() {
// let response = this.response; if (this.readyState === 4){
// console.log(response); let response = this.response;
// } console.log(response);
// }; }
// xhttp.open('GET', `../../server/controller/auth/DetailFact.php?subscribe=1&id=${id}&uuid=${uuid}`, true); };
// xhttp.send(); xhttp.open('GET', `../../server/controller/auth/DetailFact.php?subscribe=1&id=${idUser}&uuid=${uuid}`, true);
xhttp.send();
}else{ }else{
subscribeButton.innerHTML = "Subscribe"; subscribeButton.innerHTML = "Subscribe";
// xhttp = new XMLHttpRequest(); console.log("sub");
// xhttp.onreadystatechange = function() { xhttp = new XMLHttpRequest();
// if (this.readyState === 4){ xhttp.onreadystatechange = function() {
// let response = this.response; if (this.readyState === 4){
// console.log(response); let response = this.response;
// } console.log(response);
// }; }
// xhttp.open('GET', `../../server/controller/auth/DetailFact.php?subscribe=0&id=${id}&uuid=${uuid}`, true); };
// xhttp.send(); xhttp.open('GET', `../../server/controller/auth/DetailFact.php?subscribe=0&id=${idUser}&uuid=${uuid}`, true);
xhttp.send();
} }
// loadpage(id); loadpage(idContent);
}
function getCookie(cookieName) {
const name = cookieName + "=";
const decodedCookie = decodeURIComponent(document.cookie);
const cookieArray = decodedCookie.split(';');
for (let i = 0; i < cookieArray.length; i++) {
let cookie = cookieArray[i].trim();
if (cookie.startsWith(name)) {
return cookie.substring(name.length);
}
}
return null;
} }
\ No newline at end of file
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