Fix dynamic API base path for server deployment
This commit is contained in:
+4
-2
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user