I recently asked this question and it was answered professionally by Serge.
However, while I was trying to put the working code into an Adapt Learning Course (https://www.adaptlearning.org/),,) it could not work. I hence asked on the Adapt Learning Community forum and received this reply: https://community.adaptlearning.org/mod/forum/discuss.php?d=3431
Summary of reply from Adapt: I should use JQuery AJAX (because it is inbuilt into the Adapt Learning framework) instead of XMLHttpRequest.
I then tried to make a similar code work in the browser:
This is a screenshot to show that the XMLHttpRequest approach works to post data to SurveyJS:
Please advise as to how to use JQuery AJAX instead of XMLHttpRequest. Thanks!
Hello,
To be honest - I've not checked it, but I've reviewed our code and found that in AJAX we do not stringify data, e.g. code that updates survey JSON:
$.ajax({ url: "UrlToYourWebService", type: "POST", data: { surveyId: yourEditUniqueSurveyI, surveyText : editor.text }, success: function (data) { callback(saveNo, data.isSuccess); }, error: function (xhr, ajaxOptions, thrownError) { callback(saveNo, false); alert(thrownError); } });
Thanks, Serge
SurveyJS Team
Hi Serge,
You are right!
I modified the code to be like this and it works in the browser.
var data = { postId: 'someID', surveyResult: JSON.stringify(newSurvey.data) }; // You need to know the postId and survey.data $.ajax({ type: "POST", url: "https://dxsurveyapi.azurewebsites.net/api/Survey/post/", data: data, //no further stringification success: success });
Now for Adapt Learning… Hope it works.