$.getJSON not working when using getSongBPM - javascript

New to this, please excuse my ignorance.
I would like to get the bpm of a song from getsongbpm public api. There is no data being outputted to the console.
// api key has been changed
$.getJSON("https://api.getsongbpm.com/song/api_key=f9af182c18730&id=983pB", function(data){
console.log(data);
var tempo = data.song.tempo;
console.log(tempo);
$(".bpm").append(tempo);
});
I expect the console to have the output of the data in JSON format. I used this video for reference.
https://www.youtube.com/watch?v=InoAIgBZIEA

You have to fix that header problem with 'Cross-origin resource sharing (CORS)' or for testing only you can install 'Moesif CORS' chrome plugin and it works.

Related

How to query JSON with JS API to return JSON properties?

Apologies if this seems basic to some, but I'm new to JS/node.js/JSON and still finding my way. I've searched this forum for an hour but cannot find a specific solution.
I have a basic website setup running of a local Node.js server along with 2x JSON data files with information about 32x local suburbs.
An example of an API GET request URL on the site would be:
.../api/b?field=HECTARES
The structure of the JSON files are like:
JSON Structure
In the JSON file there are 32x Features (suburbs), each with it's own list of Properties as shown above. What I am trying to do is use the API 'field' query to push all the HECTARES values each of the 32x Features into a single output variable. The code below is an example of how far I have got:
var fieldStats = [];
var fieldQ = req.query['field'];
for (i in suburbs.features) {
x = suburbs.features[i].properties.HECTARES;
fieldStats.push(x);
}
As you can see in the above "HECTARES" is hard-coded - I need to be able to pass the 'fieldQ' variable to this code but have no idea how to.
Advice appreciated!
Exactly the same syntax you are using just above:
suburbs.features[i].properties[fieldQ];

Three .json files 'StockChart' - highcharts

Please help by taking StockChart. Pinning three .json files as in the example , But does not work. The code is below:
www.jsfiddle.net/d8xwjxg7/2
You have an error in your code:
$.getJSON('http://www.iklimat.pl/'+name()+'.php', function (data) {
Should be:
$.getJSON('http://www.iklimat.pl/'+ name +'.php', function (data) {
Since name is a string not a function.
Also, this will not work in a JSFiddle since you cannot load files not from the site the javascript is running on without the endpoint you are accessing setting the access-allow-control-origin header.
EDIT:
I have sorted out the issue you were having getting data, however there is an issue with that data.
http://jsfiddle.net/d8xwjxg7/5/

Script error: "Unable to get value of the property 'split': Object is null or undefined

I searched around, and couldn't find an answer to my question. I'm very new at coding, and at work, we have an application that current names that are logged in, and what they are doing.
Recently, they have changed from jquery 1.4.1 to jquery 1.8.3. Ever since then, I cannot get the results to process correctly, because of the following error;
"Unable to get value of the property 'split': Object is null or undefined"
I have the code setup to grab the results and split them;
function processAgents(xData, status) {
var avail = xData.responseText.split("|")[0];
var acw = xData.responseText.split("|")[1];
var total = xData.responseText.split("|")[2];
var breaks = xData.responseText.split("|")[3];
var pending = xData.responseText.split("|")[4];
The application is setup to open as an HTA file which opens up the PHP script.
Any help would be appreciated, please let me know if I left anything out!
Thanks!
EDIT 1
I did some more investigating, and it looks like I'm not getting data from my process request. This is how it is currently setup
function updateAgents() {
var ts1 = new Date().getTime();
$.ajax({
url: "http://SERVER/AgentSrc.php?x=" + ts1,
complete: processAgents
I'm not sure if this is processing correctly since they went to jquery 1.8.3.
EDIT 2
So after looking into it more, it doesn't appear that the script is getting the data from the server, even though I have access. If I make a local file and put the information in it, it will pull the information and split it, but if I point to the path of the file on the server, it won't get the information. But the strange thing is, if I run it using jquery 1.4.1, it pulls the data fine, but can't display it. But with 1.8.3, it doesn't allow me to pull it from the server.
thanks again!
This will give some clarity
xData.responseText.toString().split("|")[0];
(split is part of string not jQuery)
Here is a possible explanation: in earlier versions of jQuery, ajax calls returned an xmlHttpRequest (XHR) object. Recent versions return a promise (jqXHR) instead.
See this page for more details.

Unable to parse report in dhtmlx grid

On calling grid.parse(jsonstr, 'json') in js code the report is not getting displayed nor it throws any error though all the headers are getting displayed. Code below:
function getReportData(data) {
var gr = new dhtmlXGridObject('gridbox');
gr.selMultiRows = true;
gr.setHeader(data['tVals']['header']);
gr.setInitWidths(data['tVals']['init_widths']);
gr.setColAlign(data['tVals']['col_align']);
gr.setColTypes(data['tVals']['col_types']);
gr.setColSorting("str,str");
gr.init();
gr.parse(data['gData'], 'json');
}
PS: data has all the relevant information required by the code.
Also my html has following js imports:
dhtmlxcommon.js
dhtmlxgrid.js
dhtmlxgridcell.js
dhtmlxtreegrid.js
dhtmlxgrid_json.js
dhtmlxgrid_hextra.js
jquery version 1.6.1
The issue is seems to be in the format of your JSON. Can you provide a sample of your JSON string?
You can find an example of valid JSON supported by dhtmlxGrid here:
http://docs.dhtmlx.com/doku.php?id=dhtmlxgrid:syntax_templates#json_format_details
It would really help if you posted your JSON format, however I think I know what your problem is:
There are two formats of JSON that you can use in DHTMLX ( more details on https://docs.dhtmlx.com/grid__data_formats.html#jsonformat)
So the solution to your issue should be very simple.
Change
gr.parse(data['gData'], 'json');
to
gr.parse(data['gData'], 'js');

can not .getJSON request to work

My state legislature website offers a restful api.
What is the correct javascript / jquery code to fetch the value of kslegislature.org/li/api/v5/rev-1/bill_listing/
into a variable?
I can not seem to construct a working .getJSON request to pull the data.
Ultimately I want to be able to work with values like
var kslegBills = RETURNED DATA;
console.log(kslegbills.content[1].BILLNO)
complete API guide available here: http://www.google.com/url?sa=D&q=http://kslegislature.org/kliss_restian_interface_guide_v5.odt
A gentle shove in the right direction would be greatly appreciated.
jQuery.getJSON("http://www.kslegislature.org/li/api/v5/rev-1/bill_listing/&callback=?", [], function(data, textStatus) { var kslegbills = data; alert(textStatus); } )
UPDATE:
Thanks to #JackWinks I was able to get a working request through a PHP wrapper. Working model at http://kansasgrassroots.com/files/kslegbills/
It works in chrome, but not firefox or safari. I suspect it is because of the large size of the request that FF and Safari are timing out before data is returned.
I didn't find any key word about 'jsonp' in that document, so does that api support jsonp?

Categories