Reputation: 1576
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)
});
}
Upvotes: 2
Views: 701
Reputation: 131
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)
})
Upvotes: 3