Webservice JSON data not showing in HTML ID's. | XM Community
Question

Webservice JSON data not showing in HTML ID's.


Badge +1

Hello,
We developed our own webservice which we query and set as embedded data in a field called

sample.0
. We know the call works because the embedded data fields show up when we generate test responses. This field looks like this (but repeated 50 times for 50 loop & merge tasks)
[{feature:Star Wars: Rebels,topic:movies_tv_shows,label:Movie or TV-Show},{feature:Hereditary,topic:movies_tv_shows}]
We then have this in the JS:


var task = parseInt("${lm://Field/1}");

var featuresJson = "${e://Field/sample.0}"

var features = JSON.parse(featuresJson);

/* tried jquery */
jQuery("#feature").html(features[task-1].feature);

/* also tried my elementID */
document.getElementById("feature").innerHTML = features[task-1].feature;
And this in the HTML to display the values one by one:
Do you like
However, I cannot get any of the elements to show up. I also tried just showing the task we're in from this field but I can't get anything to show in the question text.


2 replies

Userlevel 3
Badge +2

i will add console.log("featuresJson",featuresJson) after reading the sample.0
var featuresJson = "${e://Field/sample.0}"
console.log("featuresJson",featuresJson)
just to make sure i can read featureJson

Userlevel 7
Badge +27

Instead of:
features[task-1].feature
Try:
features[task-1]['feature']

Leave a Reply