I have written a simple jsPsych script that greets the participant, then thanks them for their participation after they press any key. Trial data is then sent to the server script via ajax. When the participant hits 'OK' on the thank you window, the page refreshes and sends the participant back to the start of the experiment.
How do I stop the script from automatically refreshing the page? Here is the relevant bit of code:
jsPsych.init({
timeline: timeline,
on_finish: function() {
$.ajax({
type: "POST",
url: "/experiment-data",
data: jsPsych.data.get().json(),
contentType: "application/json"
})
.done(function() {
alert("Thank you!")
window.location.href = "/";
})
.fail(function() {
alert("A problem occurred while writing to the database. Please contact the researcher for more information.")
window.location.href = "/";
})
}
})
</script>
</html>