Yahoo API Call
A simple demo to show how we can parse JSON data using jQuery.getJSON()
by tickietick
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/firebug-lite/1.4.0/firebug-lite.min.js"></script>
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
<div id="body">
<h1>Parse JSON data using jQuery.getJSON()</h1>
<hr/>
<table border="1">
<tr>
<td>Url:</td>
<td><a class="myLink">The Google Geocoding API</a>
</td>
</tr>
<tr>
<td>Address:</td>
<td id="address"></td>
</tr>
<tr>
<td>Latitude:</td>
<td id="latitude"></td>
</tr>
<tr>
<td>Latitude:</td>
<td id="longitude"></td>
</tr>
</table>
</div>
CSS
body {
font-size: 75%;
font-family:"Segoe UI", Verdana, Helvetica, Sans-Serif;
}
#body {
clear: both;
margin: 0 auto;
max-width: 534px;
}
table {
border-collapse: collapse;
border-spacing: 0;
margin-top: 0.75em;
border: 0 none;
margin-top:35px;
}
#body td {
padding:15px 30px 15px 10px;
}
#body tr td:nth-child(1) {
font-weight:bold;
}
#address {
width:400px;
}
JavaScript
// The Google Geocoding API url used to get the JSON data
//var geocodingAPI = "http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true";
var geocodingAPI = "https://query1.finance.yahoo.com/v7/finance/quote?symbols=PE"
console.log("running...");
$.getJSON(geocodingAPI + "?callback=?",function(json){
console.log(json);
});
$.ajax({
url: 'https://query1.finance.yahoo.com/v7/finance/quote?symbols=PE',
data: myData,
type: 'GET',
dataType: 'jsonp',
success: function() { alert("Success"); },
error: function() { alert('Failed!'); },
beforeSend: setHeader
});
/*
$.getJSON(geocodingAPI, function (json) {
// Set the variables from the results array
var address = json.results[0].formatted_address;
console.log('Address : ', address);
var latitude = json.results[0].geometry.location.lat;
console.log('Latitude : ', latitude);
var longitude = json.results[0].geometry.location.lng;
console.log('Longitude : ', longitude);
var types = json.results[0].address_components[0].types[0];
var long = json.results[0].address_components[0].long_name;
console.log('type "' + types + '": ' + long);
// Set the table td text
$('#address').text(address);
$('#latitude').text(latitude);
$('#longitude').text(longitude);
});
// Caching the link jquery object
var $myLink = $('a.myLink');
// Set the links properties
$myLink.prop({
href: geocodingAPI,
title: 'Click on this link to open in a new window.'
}).click(function (e) {
e.preventDefault();
window.open(this.href, '_blank');
});*/