0

I have the following Codepen working with a very simple example of SurveyJS. It uses the following JSON:

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

    ]
}

When I try to use a remote file for the JSON the new Codepen is not working.

I tried requesting the JSON as follows:

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

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

I'm just starting to learn a bit of Javascript so appreciate any help with this.

1 Answer 1

1

I've slightly modified your 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");
});

And your survey JSON has an error - an extra comma

By the way - any example on https://surveyjs.io/Examples/Library/ can be opened in pluker via single mouse click on the Edit in Plunker button

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.