【问题标题】:Issue loading external JSON with SurveyJS使用 SurveyJS 加载外部 JSON 时出现问题
【发布时间】:2018-11-19 16:39:38
【问题描述】:

我有以下Codepen 使用一个非常简单的SurveyJS 示例。它使用以下 JSON:

var json = {
    "questions": [{
            "type": "text",
            "title": "Test question 1",
            "name": "Test question"
        },
        {
            "type": "comment",
            "title": "Test question 2",
            "name": "Test question 2"
        },

    ]
}

当我尝试对 JSON 使用 remote 文件时,new Codepen 不起作用。

我尝试按如下方式请求 JSON:

var giturl = "https://gist.githubusercontent.com/flowtrader2016/cdb63289fc3b4c81df9186e339233ffa/raw/1ee651735f501d5288082a0f3147ea48dc07911c/surverytest.json"

$.getJSON( giturl, function (data) {
      var json = data
});

我刚刚开始学习一点 Javascript,因此感谢任何帮助。

【问题讨论】:

    标签: javascript jquery json surveyjs


    【解决方案1】:

    我稍微修改了你的 codepen - https://codepen.io/anon/pen/ZmxGzW

    $(document).ready(function() {
      console.log("ready");
      var giturl = "https://gist.githubusercontent.com/tsv2013/43c1e94c6e663e242d772ba9f79e8c2f/raw/1a9378226b633459037c798cf44354b631f9a9c9/surverytest.json";
    
        $.ajax({
          type:"GET",
          url: giturl,
          crossDomain: true,
          success: function (data) {
            console.log("received: " + JSON.stringify(data));
            var survey = new Survey.Model(JSON.parse(data));
    
            survey
                .onComplete
                .add(function (result) {
                    document
                        .querySelector('#surveyResult')
                        .innerHTML = "result: " + JSON.stringify(result.data);
                });
    
            $("#surveyElement").Survey({model: survey});
    
          }
        });
    
        console.log("sent");
    });
    

    您的调查 JSON 有一个错误 - 一个额外的逗号

    顺便说一句 - https://surveyjs.io/Examples/Library/ 上的任何示例都可以通过单击 Edit in Plunker 按钮在 pluker 中打开

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-17
      • 2010-12-20
      • 1970-01-01
      • 1970-01-01
      • 2021-03-27
      相关资源
      最近更新 更多