Skip to content

Instantly share code, notes, and snippets.

@fischerbach
Last active December 20, 2020 08:36
Show Gist options
  • Save fischerbach/4b041d1c27c6e0a902d9f3cfff9021c7 to your computer and use it in GitHub Desktop.
Save fischerbach/4b041d1c27c6e0a902d9f3cfff9021c7 to your computer and use it in GitHub Desktop.
Code for article
Survey.StylesManager.applyTheme("modern");
var surveyJSON = {"pages":[{"name":"page1","elements":[{"type":"rating","name":"rate","title":"On a scale of one to five, how likely are you to recommend my article to a friend or colleague? *","minRateDescription":"(Most unlikely)","maxRateDescription":"(Most likely)"}]}]};
function sendDataToServer(survey, options) {
//Display information about sending data
options.showDataSaving();
$.ajax({
url: 'https://script.google.com/macros/s/AKfycby_XZaWjAb7DMbtXdOsEsPiwS3lM4NkLPhi5f3D1fdhCatn5sOQ0r2v/exec',
type: 'post',
data: JSON.stringify(survey.data),
//We need tell web app that we use plain text.
headers: {
"Content-Type": "text/plain"
},
processData: false,
complete: function(res, status) {
if (status == 'success') {
//Show that data was send successfully
options.showDataSavingSuccess();
}else {
//Display retry button in case of error
options.showDataSavingError();
}
},
});
}
var survey = new Survey.Model(surveyJSON);
$("#surveyContainer").Survey({
model: survey,
onComplete: sendDataToServer
});
@fischerbach
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment