JS Code handles code 302 redirect properly now

This commit is contained in:
Jan 2024-06-15 19:49:41 +02:00
parent 3a21fb0914
commit f7f5586d7a
6 changed files with 89 additions and 84 deletions

View File

@ -351,7 +351,7 @@ def sendpage_json():
# Now move to the next stimulus or block
update_session()
print("now redirect and reload the page")
return redirect("/jsonform")
def update_session():

View File

@ -1,4 +1,78 @@
{
"Block 4":{
"type": "TaskTemplate",
"tempalte": "standard_template.html",
"number_of_pages":"3",
"stimuli":{
"type":"single_video",
"order": "random",
"list":{
"video_1":"https://www.youtube-nocookie.com/embed/VtnwHmabyzo?si=H3rrG-GHtlSymR70",
"video_2":"https://www.youtube-nocookie.com/embed/EL76Ok4r0aQ?si=hqUm8eUUfX39NN4L",
"video_3":"https://www.youtube-nocookie.com/embed/XTMIomsXxKM?si=r2zB6OKERH6Jdpi6"
},
"configuration":{
"embed":"yt"
}
},
"questions":{
"question1":{
"type": "likert",
"name": "likertscale",
"text": "How would you rate this video?",
"required": "true",
"points":{
"p1":{
"value":"1",
"text":"I dont like it at all"
},
"p2":{
"value":"2",
"text":"I dont like it"
},
"p3":{
"value":"3",
"text":"I am indifferent"
},
"p4":{
"value":"4",
"text":"I like it"
},
"p5":{
"value":"5",
"text":"I like it a lot"
}
}
},
"question2":{
"type": "textinput",
"name": "text_feedback",
"text": "Here you can give us Feedback",
"required": "false",
"size": "250"
},
"question3":{
"type": "videoinput",
"text": "Here you can give us Feedback as video",
"name": "video_feedback",
"required": "false"
}
},
"database_table" :{
"table_name": "default_block3_test",
"fields": {
"likertscale":{
"type": "integer",
"nullable": "false"
},
"text_feedback":{
"type": "string",
"size": "250",
"nullable": "true"
}
}
}
},
"Block 3":{
"type": "TaskTemplate",
"tempalte": "standard_template.html",
@ -135,80 +209,6 @@
}
}
},
"Block 4":{
"type": "TaskTemplate",
"tempalte": "standard_template.html",
"number_of_pages":"3",
"stimuli":{
"type":"single_video",
"order": "random",
"list":{
"video_1":"https://www.youtube-nocookie.com/embed/VtnwHmabyzo?si=H3rrG-GHtlSymR70",
"video_2":"https://www.youtube-nocookie.com/embed/EL76Ok4r0aQ?si=hqUm8eUUfX39NN4L",
"video_3":"https://www.youtube-nocookie.com/embed/XTMIomsXxKM?si=r2zB6OKERH6Jdpi6"
},
"configuration":{
"embed":"yt"
}
},
"questions":{
"question1":{
"type": "likert",
"name": "likertscale",
"text": "How would you rate this video?",
"required": "true",
"points":{
"p1":{
"value":"1",
"text":"I dont like it at all"
},
"p2":{
"value":"2",
"text":"I dont like it"
},
"p3":{
"value":"3",
"text":"I am indifferent"
},
"p4":{
"value":"4",
"text":"I like it"
},
"p5":{
"value":"5",
"text":"I like it a lot"
}
}
},
"question2":{
"type": "textinput",
"name": "text_feedback",
"text": "Here you can give us Feedback",
"required": "false",
"size": "250"
},
"question3":{
"type": "videoinput",
"text": "Here you can give us Feedback as video",
"name": "video_feedback",
"required": "false"
}
},
"database_table" :{
"table_name": "default_block3_test",
"fields": {
"likertscale":{
"type": "integer",
"nullable": "false"
},
"text_feedback":{
"type": "string",
"size": "250",
"nullable": "true"
}
}
}
},
"Block_1":{
"type": "SinglePage",
"template": "test_page0.html"

View File

@ -35,15 +35,20 @@ document.getElementById("question_form").addEventListener("submit", function (ev
fetch("/send_json", {
method: "POST",
body: formData
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
// Handle success response
}).then(response => {
console.log('Response:', response);
// Check if response is a redirect (HTTP 3xx status)
if (response.redirected) {
console.log("Redirecting to:", response.url);
window.location.href = response.url; // Redirect to the new page
} else {
console.log("Non-redirect response received.");
// Handle other responses if needed
}
})
.catch(error => {
console.error('Error:', error);
// Handle error response
// Handle errors if fetch fails
});
});