0

是否可以使用 POST 设置 SurveyJS 调查的结果?

我可以使用 GET 来获取调查结果,但我在设置方面遇到了困难。

这是我用来获取结果的代码:

urlToSurvey = "https://dxsurvey.com/api/MySurveys/getSurveyResults/surveyID?accessKey=myKey";

$.get(urlToSurvey, function(res) {
    console.log(res);
});

我想使用 SurveyJS 将学生的进度存储在开源插件(Adapt Learning)中,因此我想直接将进度数据发布到 SurveyJS,因为我无法在插件中运行独立的 html。

任何帮助表示赞赏。谢谢!

4

1 回答 1

0

您可以检查此文件 - 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 和结果 json。您可以从服务的 MySurveys 页面获取您的 postId(https://surveyjs.io/Service/MySurveys/注意 MySurveys 页面需要授权)。

这是一个 TypeScript 代码,但我确信它可以很容易地转换为 JS。

于 2018-06-26T13:55:19.650 回答