Custom HTML Widget Examples
For estimation purposes only
These are the 2015 mill levies. These were last updated on 12/7/2015.
|
Custom Html: Ajax GET
Use the following code snippet in a Custom HTML Widget to retrieve data from a third party API.
<script type="text/javascript">
$(document).ready(function() {
var root = 'http://jsonplaceholder.typicode.com';
$.ajax({
url: root + '/posts',
type: 'GET'
}).then(function(data) {
for(var i = 0; i < 8; i++)
{
$('#ourCustomHtml').append('<span><h2>' + data[i].title + '</h2><p>' + data[i].body + '</p></span>');
}
});
});
</script>
Results
Custom Html: Ajax GET - GitHub Repos tag as C#
Use the following code snippet in a Custom HTML Widget to retrieve data from a third party API.
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
url: "https://api.github.com/search/repositories?q=language:csharp&sort=stars&order=desc",
type: 'GET',
success: function(data){
for(var i = 0; i < data.items.length; i++)
{
$('#gitHubRepos').append('<span><h2>' + data.items[i].name + '</h2><p>' + data.items[i].description + '</p></span>');
}
}
});
});
</script>
Custom Html: Ajax POST
Use the following code snippet in a Custom HTML Widget to send data to a third party API.
<button id="makeRequest">Make Request</button>
<div id="customhtmlpost"></div>
<script type="text/javascript">
var root = 'http://jsonplaceholder.typicode.com';
$(document).ready(function(){
$('body').delegate('#makeRequest', 'click', function(){
$.ajax({
url: root + '/posts',
data: {
title: 'CivicPlus',
body: 'This is a test Post.',
userId: 1
},
type: 'POST',
success: function(data){
$('#customhtmlpost').append('<span><h2>' + data.title + '</h2><p>' + data.body + '</p></span>');
}
});
})
});
</script>
Insert Zip Code To Retrieve Weather Information
Get Weather
<h3>Insert Zip Code To Retrieve Current Weather</h3>
<input type="text" id="zipCode">
<a href="#" id="getWeather" class="button">
<span>Get Weather</span>
</a>
</div>
<div id="weatherDemo"></div>
<script type="text/javascript">
$(document).ready(function() {
$('body').delegate('#getWeather', 'click', function(){
var zip = $('#zipCode').val();
$.ajax({
url: 'http://api.openweathermap.org/data/2.5/weather?zip=' + zip +',us&units=imperial&appid=fb7a9cf748542fe9d7a27816ff216a13',
type: 'GET',
dataType: 'JSONP',
success: function(data){
var icon = 'http://openweathermap.org/img/w/' + data.weather[0].icon +'.png';
$('#weatherDemo').html('<span><h2>Weather Info for ' + data.name + '</h2><p><h3>Current Conditions</h3>' +
'<div>' + UpperCaseWords(data.weather[0].description) + '<img src="' + icon + '"/></div>' +
'<div>Current Temperature: ' + data.main.temp + '</div></p>' +
'<h3>5 Day Forecast</h3>');
var id = data.id;
$.ajax({
url: 'http://api.openweathermap.org/data/2.5/forecast/daily?id=' + id + '&units=imperial&appid=fb7a9cf748542fe9d7a27816ff216a13&cnt=5',
type: 'GET',
dataType: 'JSONP',
success: function(data2){
for(var i = 0; i < data2.list.length; i++){
var today = data2.list[i];
$('#weatherDemo').append(
'<p><div><b>' + getDayOfWeek(new Date(), i) + '</b></div>' +
'<div><b>High:</b> ' + Math.round(today.temp.max) + '</div>' +
'<div><b>Low:</b> ' + Math.round(today.temp.min) + '</div>' +
'</p>');
}
}
});
$('#weatherDemo').append('</span>');
},
error: function(xhr, status, message){
alert('Error retrieving weather information for zip: ' + zip);
}
});
});
});
function getDayOfWeek(date, addDays){
date.setDate(date.getDate() + addDays);
var weekday = new Array(7);
weekday[0]= "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
return weekday[date.getDay()];
}
function UpperCaseWords(str)
{
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
</script>