faanbece faanbece - 1 year ago 133
Javascript Question

How to download silently with javascript

I am new in javascript and I have some trouble to complete an activity...

I need working, in the client side, with the information uploaded in a "special" server like this:


I want load it in main memory, without the browser show the explicit download.

I try to use some solutions, but really I have no idea how to proceed to achieve it.

... Beforehand thank you very much

(I am not a native english speaker, I apologize if I do not write well)


I decided, for the moment, use the Whatever Origin services, that returns me something I can read with $.getJSON "Without download" the file.


<script type="text/javascript">
$.getJSON('http://whateverorigin.org/get?url=' + "http://www.uninorte.edu.co/documents/71051/11558879/ExampleData.json/0a635cdd-ccdd-4a1c-8c88-b53bea431458" + '&callback=?', function(data){

Thank you for yours responses, really you gave me lights in order to solve it

Answer Source

Regarding silent part

Your browser is always aware of the network requests which are made from JS. Therefore, the user can always see all the requests and responses by opening developer tools.

Now coming to loading a remote json to the memory in the client

Since you mentioned you are relatively a newbie in JS, I am going to cover the very basic, so please bear with me if you already know it

You need to make an ajax call using an XMLHttpRequest as shown here

However, most people use some library like jQuery while working to abstract checking state of the request and other trivial tasks. This results in making an ajax call as simple as calling a method and providing a callback method to process the response.

  url: '/path/to/file',
  type: 'default GET (Other values: POST)',
  dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
  data: {param1: 'value1'},
.done(function() {
.fail(function() {
.always(function() {

You may find the example at below link.


P.S.: Due the less reputation points, I can neither post any supporting images nor more than two links.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download