I am trying to grab a JSON file from a website (Trello.com). when I navigate to the web address of the JSON file in IE (or any browser) I am presented with the option to save it or to open it.
So I think to myself "this should be quite easy then".
However I've got some limitations on how to implement it.
I need to display data from the JSON on CRM 2013.
The displaying of the data isn't the issue, it's grabbing the JSON file from the website.
An example URL to use would be https://trello.com/1/boards/dgbi8Gng
I've been trying to use Ajax and JSONP but am encountering issues (likely due to my lack of experience with them).
Could anyone help out a frustrated fellow? Maybe some example code that could be implemented in CRM and a quick explanation?
Many Thanks
You need to include your application key in the url e.g.
https://trello.com/1/boards/dgbi8Gng?key=substitutewithyourapplicationkey
Then it's just a standard request (assuming you're using jQuery)
var url = "https://trello.com/1/boards/dgbi8Gng?key=[YOUR KEY]";
$.getJSON( url, function( data ) {
console.log(data);
});
Full details are here:
https://trello.com/docs/gettingstarted/#getting-an-application-key
Related
I need to get the URL of each video in a library with JavaScript (I don't know how many videos will be in the library). I also need to get specific information about each video, such as date created. How would I do this? I am using a Script Editor web part to execute the JavaScript.
You could use rest API to get the information you wanted.
/_api/web/lists/GetByTitle('library title')/files
/_api/web/GetFolderByServerRelativeUrl('/sites/dev/Doc')/Files
Get to know the SharePoint REST service
Rest call with the below url will get you what you looking for
/_api/web/lists/getbytitle('" + youlistname + "')/items?$select=*,FileRef/FileRef"
How do I read a JSON file that is hosted on another server?
There is a site which hosts JSON data and I want to access it through JavaScript.
The JSON data is on the Open Notify API.
The problem with other questions asked and things I found on the Internet don't help me because they're all about local JSON files!
I also tried jQuery but it didn't work. Anyways, when I looked at the syntax, the script part of the function had to be a PHP script on the server. I put the JSON file in that spot but nothing happened. I used the $.get() method.
I would really appreciate it if someone answered me.
Thanks!
In pretty much the same manner you'd call a local JSON file, you can fetch the contents of an online JSON file from another URL.
That being said, you should keep in mind that the URL should provide cross-origin headers to allow your domain to request that resource.
The URL you mentioned has those headers and you can use it. However, their web server doesn't support HTTPS so I can't use it as an example here, thus I will use this JSON for the sake of the example:
$.getJSON(
"https://jsonplaceholder.typicode.com/todos/1",
function( data ) {
$('div#title span').html(data.title);
$('div#completed span').html(data.completed?'true':'false');
}
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='title'>Title: <span></span></div>
<div id='completed'>Completed: <span></span></div>
On my ASP.NET web api backend I have Aspose.Cells make a spreadsheet. I have been saving it locally and the spreadsheet is good, but now that I am trying to host it on a server I have to send the spreadsheet through the HTTP response. At the end of my web api route I have the following code:
workbook.Save(HttpContext.Current.Response, output.xls, ContentDisposition.Inline, new XlsSaveOptions());
HttpContext.Current.Response.End();
This sends the response which can be seen here in Chrome dev tools:
As you can see, the body is just random gibberish mostly which I'm assuming is just binary. On the client my typescript inside the subscribe method which receives the response looks like this:
var blob = new Blob([data._body], { type: 'application/vnd.ms-excel' });
var url = window.URL.createObjectURL(blob);
window.open(url);
This saves the file with a name like f811c3bc-2eea-4394-b463-93c61ccc7677.xls, and inside the spreadsheet it again just looks like gibberish, after excel warns me that the file is a different format than the extension:
The words 'detail' and 'site detail' are words that should be in there, so at least something that I want shows up, but its obviously not quite there. What am I doing wrong? This is supposed to be a spreadsheet with 20+ tabs and up to a couple thousand rows on a few of the tabs, and less than 10 on others.
EDIT: I have fixed my problem for anyone searching from the future. On your HTTP request options, you need to set the response type to ArrayBuffer. I also switched to using Filesaver.js although I'm not sure if that is actually needed or not.
We are afraid, Web Browsers don't understand XLS (Excel 2003) and XLSX (Excel 2007 and newer) format. Only Microsoft Excel understands it. It means, you cannot show your Excel files in Web Browsers. You can just ask the user to download them and then users will have to open them in their Microsoft Excel application on their own.
However, some of the browsers understands (or they have plug-ins) Pdf format. If you want to show your Excel file contents, then render it to Pdf using Aspose.Cells and then user will be able to view it inline if he is using Google Chrome, FireFox etc.
Anyhow, you will have to send it as attachment. Please change your code like this.
workbook.Save(HttpContext.Current.Response, output.xls,ContentDisposition.Attachment, new XlsSaveOptions());
HttpContext.Current.Response.End();
Note: I am working as Developer Evangelist at Aspose
I have an URL, say
abc.com/download?fileid=123&entity_id=456&sid=101
which downloads an excel file when I click the link. Instead of downloading it, I want to read its contents with HTML & javascript in order to process the information automatically.
Is there a way to do that? I am not familiar with web programming therefore I am not sure how to proceed. I have tried the following, but nothing happened.
var excel = new ActiveXObject("Excel.Application");
var excel_file = excel.Workbooks.Open("url here");
var excel_sheet = excel_file.Worksheets("Sheet1");
var data = excel_sheet.Cells(1,2).Value;
alert(data);
edit: my question is different from the linked one as I am also trying to figure out how to get the initial raw data which will be parsed once I get it into a variable (however simple the answer might be, I could not find it anywhere else and this is my first practice with web so I couldn't find a way around).
Can the code above access the file in the URL? I do not know how to test it and writing alert(data) returns no result. How do I know I have some data to work with, before I start parsing?
edit2: following returns something when urlString="www.google.com", but it do not return anything with the URL I have, probably because it is a download link.
$.get(urlString, function(data, status){
alert("Data: " + data + "\nStatus: " + status);});
Microsoft Exel files (xls|xlsx) are proprietary format. You need to do a lot of work in order to transform them into a form that can be manipulated with JavaScript and injected into a html document.
Luckily some geeky boffins have done all the hard work already, in the form of the JS-XLS and JS-XLSX JavaScript libraries.
See this page # CodeTheory.com for a brief breakdown of their capabilities.
I have a .csv file that I wish to load that contains information that the .HTML page will format itself with. I'm not sure how to do this however,
Here's a simple image of the files: http://i.imgur.com/GHfrgff.png
I have looked into HTML5's FileReader and it seems like it will get the job done but it seems to require usage of input forms. I just want to load the file and be able to access the text inside and manipulate it as I see fit.
This post mentions AJAX, however the thing is that this webpage will only ever be deployed locally, so it's a bit iffy.
How is this usually done?
Since your web page and data file are in the same directory you can use AJAX to read the data file. However I note from the icons in your image that you are using Chrome. By default Chrome prevents just that feature and reports an access violation. To allow the data file to be read you must have invoked Chrome with a command line option --allow-file-access-from-files.
An alternative, which may work for you, is to use drag the file and drop into onto your web page. Refer to your preferred DOM reference for "drag and drop files".
You can totally make an ajax request to a local file, and get its content back.
If you are using jQuery, take a look at the $.get() function that will return the content of your file in a variable. You just to pass the path of your file in parameter, as you would do for querying a "normal" URL.
You cannot make cross domain ajax requests for security purposes. That's the whole point of having apis. However you can make an api out of the $.get request URL.
The solution is to use YQL (Yahoo Query Language) which is a pretty nifty tool for making api calls out of virtually any website. So then you can easily read the contents of the file and use it.
You might want to look at the official documentation and the YQL Console
I also wrote a blog post specifially for using YQL for cross domain ajax requests. Hope it helps
You can try AJAX (if you do not need asynchronous processing set "async" to false. This version below ran in any browser I tried when employed via a local web server (the address contains "localhost") and the text file was indeed in the UTF-8-format. If you want to start the page via the file system (the address starts with "file"), then Chrome (and likely Safari, too, but not Firefox) generates the "Origin null is not allowed by Access-Control-Allow-Origin."-error mentioned above. See the discussion here.
$.ajax({
async: false,
type: "GET",
url: "./testcsv.csv",
dataType: "text",
contentType: "application/x-www-form-urlencoded;charset=UTF-8",
success: function (data) {
//parse the file content here
}
});
The idea to use script-files which contain the settings as variables mentioned by Phrogz might be a viable option in your scenario, though. I was using files in the "Ini"-format to be changed by users.