Is there a way I can retrieve the JSON file from server - javascript

Referring to my question above, the reason I want to retrieve the file is that I want to know how it is structured so I can make the script that I copied work using my data instead.
Currently, the $.getJSON url includes the string "callback=?" in it.
So is there anyway, I can peek through or see how the data is structured in the file thats inside the $.getJSON url string?
actually, Im following along a demo below
https://code.google.com/r/kgraham-flr-map/source/browse/examples/medicare-dynamic-ds.js?spec=svn72fd5de93cf24b0b2baa5d2678d9518741e3d80b&r=72fd5de93cf24b0b2baa5d2678d9518741e3d80b
Tthe script in question has the $.getJSON('https://storelocator-go-demo.appspot.com/query?callback=?' to parse the data.
When I tried opening the url, I get this error strconv.ParseFloat: parsing "": invalid syntax
I want to see how the JSON file is structured so I can replace it with my own data instead.
Hope this clears my question.

From the comments:
so you mean the error that I got when trying to open the json file is due to a server problem?
Well, it could give you a more useful error message. The problem is that you're not giving it the arguments it requires.
If I go to:
https://storelocator-go-demo.appspot.com/query?callback=foo
...then like you, I get that error. But if I give it arguments (these are cribbed from the examples link you gave):
https://storelocator-go-demo.appspot.com/query?callback=foo&lat=-29.292219923932738&lng=137.763512&n=-10.691329506145314&e=167.382652625&s=-47.89311034172016&w=108.14437137499999&audio=&access=&_=1364633286163
I get back a valid JSONP response.

Related

PowerBi: Query HTML table

What I need
I need to retrieve data from this source . Let's assume I must use only PowerBi for this.
What I did so far
If I use the basic web source option, then the query is just basically an htlm parsing with which I can easily get the data found in the html scope of the page, example:
Source:
The steps I'm following through Web source option:
Query:
(to simplify the example, assume we don't need the dates)
You can download that example .pbix file here.
The problem
The problem is that I need more data, which can't be accessed through the html preview. For example, let's imagine I need to retrieve the data from January 2010 to April 2020. Those king of queries can only be done via this button located in the webpage (which exports the requested data to an Excel workbook):
The idea is to get this process automated, so going to the source and export the excel file all the time is not an option.
Inspecting the element I realized that what it does is execute a javascript function:
The question
As a PowerBi/PowerQuery noob I wonder: Is there any way I can get that data directly with PowerBi (maybe calling the js function somehow)? If there is so, then how?
Thank you in advance.
The solution to my case was to use URL parameters to retrieve de data without parsing the html table.
❌Original URL I was using:
https://gee.bccr.fi.cr/indicadoreseconomicos/Cuadros/frmVerCatCuadro.aspx?idioma=1&CodCuadro=%20400
✔️New URL for the query, adding some parameters:
https://gee.bccr.fi.cr/indicadoreseconomicos/Cuadros/frmVerCatCuadro.aspx?idioma=1&CodCuadro=%20400&Idioma=1&FecInicial=2010/01/01&FecFinal=2040/01/01&Filtro=0&Exportar=True
This procedure only works in this case, because obviously the parameters will not be the same on other web pages.
However, I post this answer to keep the main idea for those who are in a similar situation: first try with the appropriate url parameters to get the data in a different format. Of course you first must know which are the available parameters, which is a limitation.

Using Google Spreadsheet as JSON file using tabletop to datatables returns error

I'm a relative newbie when it comes to coding, especially javascript. I currently am trying to populate a table from a google spreadsheet, which will update when the spreadsheet is.
I followed this tutorial word for word (basically all you need to do is replace the key with your own to specify your spreadsheet, and make sure its both published and public, which I've done)
http://dataforradicals.com/the-absurdly-illustrated-guide-to-sortable-searchable-online-data-tables/
I just get a bad request 400 error referring to my spreadsheet. If I visit the spreadsheet generated directly I just get the words...
"Invalid query parameter value for sq."
https://spreadsheets.google.com/feeds/list/1UcfO9GHePQrcixZB_R9uVXr1vHVqVTDg7DdsOjpm-K0/od6/public/values?alt=json-in-script&sq=&callback=Tabletop.callbacks.tt140241226993949106
I can visit my spreadsheet with the link I was given when I published it here..
[maximum links reached but the structure is different]
As you can see the domain structure is different. I fear that "Tabletop to Datatables" is adding an outdated url to the start of that link but can't find where it actually applies it.
The only reason I would think thats not happening is because the example in the tutorial still works! And the link it refers to is the old style URL too
I'm baffled, please help if you can. All suggestions appreciated
The query string includes a parameter without a value, &sq=.
https://spreadsheets.google.com/feeds/list/1UcfO9GHePQrcixZB_R9uVXr1vHVqVTDg7DdsOjpm-K0/od6/public/values?alt=json-in-script&sq=&callback=Tabletop.callbacks.tt140241226993949106
^^^^
Try this, with that parameter completely removed...
https://spreadsheets.google.com/feeds/list/1UcfO9GHePQrcixZB_R9uVXr1vHVqVTDg7DdsOjpm-K0/od6/public/values?alt=json-in-script&callback=Tabletop.callbacks.tt140241226993949106
There is an updated version of this project. Any necessary updates are included here:
https://github.com/scottpham/tabletop-to-datatables
Try with the updated versions of all js libraries.
Check the link and remove the extra string after pub. That part of link is not necessary and may cause issues.
According to google:
The 400 Bad Request error is an HTTP status code that means that the request you sent to the website server, often something simple like a request to load a web page, was somehow incorrect or corrupted and the server couldn't understand it.
Good luck

Can one issue a GET to a JSON file in the server with a key?

I'm currently trying to do an auto-suggestion exercise where the JSON file is located on a server, and I'm not sure if I'm understanding the webdev terminology correctly. In one of the requirements it says:
"On the keyup [since there's an input field], issue a GET to the server with the value of input key and the name of a callback function as parameters."
I've issued a GET to a json file on a server before, but I'm confused how one can issue a GET to the file on the server with a key as a parameter for a JSON file. Is this even possible?
Web Terminologoy: You don't issue a GET Request for a file, you issue a GET request for a ressource identified by a URL
the HTTP request line might look like this:
GET /some/thing HTTP/1.0
parameters can be part of the URL, for example:
GET /some/thing?color=red&number=3 HTTP/1.0
Learn everything about URLs in the RFC http://www.ietf.org/rfc/rfc3986.txt
Now maybe in your first example the ressource /some/thing.json points to really was a static json file. But for this exercise, you'll probably need a program running on the webserver, and outputting json.

Read Rewritten URL - javascript

I need to read the original URL from the rewritten path.
this is how i do url rewrite in my webapplication. I don't have codebehind in my application. So i read everything through javascript and call a webservice. While calling the webservice, i need to read query parameter ID and pass it.
Is my url rewrite method is right? if so, how can i read the original URL i.e. pages/products.aspx?ID=123. Because in my browser address bar it shows only product.aspx, i get the same through javascript.
Don't know whether right or wrong way, anyhow I managed to get the query string using JavaScript.
The query string was not visible in the browser window, but in the form tag it is available. So I get that using document.getElementsByTagName('form')[0].action, and completed my task.

Weatherbug REST JSON

I have a solid understanding of HTML and javascript. I have no experience with JSON. I would like to get the data from the URL http://i.wxbug.net/REST/Direct/GetUv.ashx?zip=21044&api_key=vxwdyz3evgtvuv9d5e53sckc and display it on a webpage. I have looked around for a simple tutorial that explains how to retrieve JSON data from a URL without prevail. Can someone point me in the right direction?
If your page is in different domain, you will encounter the "...not allowed by Access-Control-Allow-Origin" error when you use javascript to access it. However, you could make a proxy page in the server side, fetch the data and then output data.
And then, you could get the data, for example, if you use jQuery, it is very easy like:
$.getJSON(your_proxy_page_url,function(data) {
console.log(data);
});
You could also try to take look at this post, maybe it can help you out:
http://docs.jquery.com/Release:jQuery_1.2/Ajax#Cross-Domain_getScript

Categories

Resources