【发布时间】:2015-03-23 20:32:45
【问题描述】:
我正在尝试使用 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 控制器中的 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)
});
}
【问题讨论】:
标签: javascript angularjs