I have a REST API that produces JSON Output as follows:
[{"case": 2005608875,
"filepath": "/x/eng/cs-data/latx/dev/20150510_uploads/wilp/perfstat_20150415_001256/node/10.95.172.19/output.data",
"datatype": "perf8",
"perfdateend": "2015-04-15T02:15:37-04:00",
"userid": "wilp",
"filename":"perfstat_20150415_001256.zip",
"version": "v8.1 ",
"hosts": [{"filer": "cluster1-01",
"hostname": "10.95.172.18", }],
"perfid":"98"}]
I am trying to display this data in HTML, but I can not do this, Here is my HTML + jQuery div:
<div class="widgetcontent">
<select>
<option>
96
</option>
<option>
97
</option>
<option>
98
</option>
<option>
99
</option>
</select>
<button class="topcoat-button--cta">Get Data!</button>
</div>
<div class='content'> </div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="js/pull.js"></script>
and here is my jQuery (pull.js)
(function ($) {
$('button').on('click', function () {
$('.content ul').remove();
var perfid = $('select option:selected').text();
$.getJSON('http://myapiurl.com/ws/spm/search/perfid/' +perfid, function (data) {
var items = [],
$ul;
$.each(data, function (key, val) {
items.push('<li id="' + key + '"><span class="Case">' + val.case + '</span><br><span class="UserID">' + val.userid + '</span></li>');
});
if (items.length < 1) {
items.push('<li>No Data Found!</li>');
}
$ul = $('<ul />').appendTo('.content');
$ul.append(items);
});
});
}(jQuery));
I pull my hair from this from 2 days and still can not understand.
source
share