[英]Is possible to load a document in-memory?
I need to get a pdf file from http://www.pdf995.com/samples/pdf.pdf using javascript so I can make a POST of this document to a REST API. 我需要使用javascript从http://www.pdf995.com/samples/pdf.pdf获取pdf文件,以便可以将此文档发布到REST API。 The pdf should stay only in-memory because I only need that document to make a post request. pdf应该只保留在内存中,因为我只需要该文档即可发出发布请求。
Is this possible to do this using browser javascript? 使用浏览器JavaScript可以做到这一点吗? I'm using angularjs. 我正在使用angularjs。
$http.post("/someUrl", json) { .... }
Yes you can store the data into local variable and pass it to other ajax call. 是的,您可以将数据存储到局部变量中,并将其传递给其他ajax调用。
window.binaryData = null;
$.ajax( {
url:'https://www.tutorialspoint.com/jquery/jquery_tutorial.pdf',
method:'GET',
success:function(data) {
window.binaryData = data;
console.log('Success => ',data);
},
error:function(error){
console.log('Error => ',error);
}
});
Response from ajax call can be set to variable on the window scope window.binaryData
. 来自ajax调用的响应可以在窗口范围window.binaryData
上设置为variable。
jsFiddle - https://jsfiddle.net/L6ge8f0w/ jsFiddle- https: //jsfiddle.net/L6ge8f0w/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.