是否可以使用POST来设置SurveyJS调查的结果?
我可以使用GET来获取调查结果,但我在设置方面遇到了困难。
下面是我用来获取结果的代码:
urlToSurvey = "https://dxsurvey.com/api/MySurveys/getSurveyResults/surveyID?accessKey=myKey";
$.get(urlToSurvey, function(res) {
console.log(res);
});我想使用SurveyJS在一个开源插件(适应学习)中存储学生的进度,所以我想直接将进度数据发布到SurveyJS,因为我不能在插件中运行独立的html。
任何帮助都是非常感谢的。谢谢!
发布于 2018-06-26 21:55:20
您可以检查此文件- https://github.com/surveyjs/surveyjs/blob/master/src/dxSurveyService.ts
以下是负责发送结果的代码:
public sendResult(
postId: string,
result: JSON,
onSendResult: (success: boolean, response: any) => void,
clientId: string = null,
isPartialCompleted: boolean = false
) {
var xhr = new XMLHttpRequest();
xhr.open("POST", dxSurveyService.serviceUrl + "/post/");
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
var data = { postId: postId, surveyResult: JSON.stringify(result) };
if (clientId) data["clientId"] = clientId;
if (isPartialCompleted) data["isPartialCompleted"] = true;
var dataStringify: string = JSON.stringify(data);
var self = this;
xhr.onload = xhr.onerror = function() {
if (!onSendResult) return;
onSendResult(xhr.status == 200, xhr.response);
};
xhr.send(dataStringify);
}必需的参数是postId和result json。您可以从服务的MySurveys页面获取postId (https://surveyjs.io/Service/MySurveys/请注意,MySurveys页面需要授权)。
这是一段TypeScript代码,但我确信它可以很容易地转换为JS。
https://stackoverflow.com/questions/50457287
复制相似问题