gpt4 book ai didi

javascript - 将 DocRaptor Web 服务与 AngularJS 一起使用?

转载 作者:行者123 更新时间:2023-11-29 19:29:07 28 4
gpt4 key购买 nike

我正在尝试使用 DocRaptor 从 AngularJS 应用生成 Excel (.xls) 文件.在尝试 DocRaptor 入门文档中所述的简单 POST 请求时,我不断收到以下错误。他们的文档声称他们支持 CORS 请求。任何帮助将不胜感激。

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.

这是我的 AngularJS Controller 中的 JavaScript 代码:

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)
});

}

最佳答案

我遇到了同样的问题。你应该发送 -

data:forDocRaptor

此外,出于某种原因,如果您使用

method:'POST'

它有效,但 $http.post 无效

所以 - 您的代码将如下所示:

$http({
method:'POST',
url: URL,
data:forDocRaptor
}).success(function(res){
console.log(res)
})

关于javascript - 将 DocRaptor Web 服务与 AngularJS 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29219813/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com