如何用javascript静默下载 [英] How to download silently with javascript

查看:1358
本文介绍了如何用javascript静默下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要在客户端工作,将信息上传到特殊服务器,如下所示:



http://www.uninorte.edu.co/documents/71051/11558879/ExampleData.json/0a635cdd-ccdd-4a1c-8c88-b53bea431458



我想在主内存中加载它,没有浏览器显示显式下载。



我尝试使用一些解决方案,但我真的不知道如何继续实现它。



...非常感谢你



(我不是英语母语者,如果我写得不好,我很抱歉)



[解决]



我决定,暂时使用无论什么来源服务,这将返回给我一些可以用$ .getJSON无需下载文件的内容。 / p>

结果:

 < 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){
alert(data.contents);
});
< / script>

谢谢你的回复,真的你给了我灯光,以解决

解决方案

关于无声部分



您的浏览器始终知道由JS生成的网络请求。因此,用户可以随时通过打开开发人员工具查看所有请求和响应。






现在加载一个远程json到客户端的内存



由于你提到你在JS中比较新颖,我将要覆盖非常基本的,所以请如果您已经知道,请与我联系



您需要使用XMLHttpRequest进行ajax调用,如 here






然而,大多数人们使用像jQuery这样的图书馆,同时在抽象检查请求状态和其他微不足道的任务。这样做一个ajax调用就像调用方法一样简单,并提供回调方法来处理响应。

  $。ajax ({
url:'/ path / to / file',
type:'default GET(Other values:POST)',
dataType:'default:Intelligent Guess(Other value:xml ,json,script或html)',
data:{param1:'value1'},
})
.done(function(){
console.log成功);
})
.fail(function(){
console.log(error);
})
.always(function() {
console.log(complete);
});

您可以在下面的链接中找到该示例。



http://api.jquery.com/jquery.getjson/



PS:由于信誉度较低,我不能发布任何支持图片,也不能发布两个以上的链接。


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:

http://www.uninorte.edu.co/documents/71051/11558879/ExampleData.json/0a635cdd-ccdd-4a1c-8c88-b53bea431458

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)

[Solved]

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

Resulted:

<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){
        alert(data.contents);
      });
 </script>

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

解决方案

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.

$.ajax({
  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() {
  console.log("success");
})
.fail(function() {
  console.log("error");
})
.always(function() {
  console.log("complete");
});

You may find the example at below link.

http://api.jquery.com/jquery.getjson/

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

这篇关于如何用javascript静默下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆