Fix dynamic API base path for server deployment

This commit is contained in:
pongpon pitisuk
2026-09-12 14:34:09 +07:00
parent 72eb7cd0c8
commit e01d01464a
9 changed files with 262 additions and 52 deletions
+4 -2
View File
@@ -15,7 +15,8 @@ async function initSurvey() {
}
try {
const data = await fetch(`/survey/api/surveys.php?action=getByLink&link=${encodeURIComponent(link)}`).then(r => r.json());
const basePath = window.location.pathname.includes('/survey') ? '/survey' : '';
const data = await fetch(`${basePath}/api/surveys.php?action=getByLink&link=${encodeURIComponent(link)}`).then(r => r.json());
if (data.error) {
showError(data.error);
@@ -249,7 +250,8 @@ async function submitSurveyResponse(e) {
const params = new URLSearchParams(window.location.search);
try {
const res = await fetch('/survey/api/responses.php?action=submit', {
const basePath = window.location.pathname.includes('/survey') ? '/survey' : '';
const res = await fetch(`${basePath}/api/responses.php?action=submit`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({