使用DocRaptor Web服务与AngularJS? [英] Using DocRaptor web service with AngularJS?
问题描述
我想生成Excel(.xls的)文件使用AngularJS应用 DocRaptor 。我不断收到以下错误,如DocRaptor的入门文档中描述的努力只是简单的POST请求时。他们的文档声称他们支持CORS请求。任何帮助将大大AP preciated。
在Chrome的错误消息:
选项https://docraptor.com/docs?user_credentials=my-api-keyXMLHtt prequest无法加载https://docraptor.com/docs user_credentials =我的API密钥。无访问控制允许来源标头的请求的资源present。原产地的http://本地主机:8000'因此不允许访问。响应有HTTP状态code 404。
下面是我在AngularJS的控制器中的JavaScript code:
VAR forDocRaptor = {
DOC:{
测试:真实,
DOCUMENT_TYPE:PDF,
//只是想现在简单的PDF
名:adoc.pdf
document_content:'< DIV> PDF生成测试< / DIV>,
严:无,
的JavaScript:真实,
标签:标签,
异步:假的
}
}$ scope.exportToExcel =功能(){ $ http.post('https://docraptor.com/docs?user_credentials=my-api-key',forDocRaptor)
.success(功能(RES){
的console.log(RES)
});}
我有同样的问题。你应该发送 -
数据:forDocRaptor
此外,由于某种原因,如果使用
方法:POST
它的工作原理,但$ http.post没有
所以 - 你的code是这样的:
$ HTTP({
方法:POST,
网址:网址,
数据:forDocRaptor
})。成功(功能(RES){
的console.log(RES)
})
I am trying to generate Excel (.xls) files from an AngularJS app using DocRaptor. I keep getting the following error, when trying just the simple POST request as described in DocRaptor's Getting Started documentation. Their documentation claims they support CORS requests. Any help will be greatly appreciated.
Error Message in Chrome:
OPTIONS https://docraptor.com/docs?user_credentials=my-api-key
XMLHttpRequest cannot load https://docraptor.com/docs user_credentials=my-api-key.
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. The response had HTTP status code 404.
Here's the JavaScript code in my AngularJS controller:
var forDocRaptor = {
"doc" : {
"test": true,
"document_type": "pdf",
//Just trying simple pdf for now
"name": "adoc.pdf",
"document_content": '<div>PDF generation test</div>',
"strict": "none",
"javascript": true,
"tag": "tag",
"async": false
}
}
$scope.exportToExcel = function() {
$http.post('https://docraptor.com/docs?user_credentials=my-api-key', forDocRaptor)
.success(function(res) {
console.log(res)
});
}
I was having the same problem. You should be sending -
data:forDocRaptor
Also, for some reason if you use
method:'POST'
it works, but $http.post does not
So - your code would look like this:
$http({
method:'POST',
url: URL,
data:forDocRaptor
}).success(function(res){
console.log(res)
})
这篇关于使用DocRaptor Web服务与AngularJS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!