I have a REST API which 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 am not able to do so, Here is my div of HTML+jQuery:
<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><!--widgetcontent-->
<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 () {
// remove resultset if this has already been run
$('.content ul').remove();
// get selected zip code from selectbox
var perfid = $('select option:selected').text();
// make AJAX call
$.getJSON('http://myapiurl.com/ws/spm/search/perfid/' +perfid, function (data) {
// do all this on success
var items = [],
$ul;
$.each(data, function (key, val) {
//iterate through the returned data and build a list
items.push('<li id="' + key + '"><span class="Case">' + val.case + '</span><br><span class="UserID">' + val.userid + '</span></li>');
});
// if no items were returned then add a message to that effect
if (items.length < 1) {
items.push('<li>No Data Found!</li>');
}
// append list to page
$ul = $('<ul />').appendTo('.content');
//append list items to list
$ul.append(items);
});
});
}(jQuery));
I am pulling my hair on this since 2 days and still cannot figure it out.