Error 500 posting http request from javascript
-
Hello,
I'm new to jsreport;I created a simple report in JSreport online, then from an html / javascript page I want to call the reporting engine.
This is my actual javascript code for the request
$.ajax({ type: "POST", url: 'https://xxxxxx.jsreportonline.net/api/report', contentType: 'application/json', dataType: 'json', data: { "template": { "shortid" : "HJI-R8mz-" }, "options": { timeout: 60000 } }, beforeSend: function (xhr) { xhr.setRequestHeader ("Authorization", "Basic " + btoa('viewer:12345678')); }, success: function( data ) { console.log( data ); } });
To simplify the process for the moment I decided to avoid passing data to the report.
Anyway I'm always getting error 500 from the browser and exactly this message in chrome consoleXMLHttpRequest cannot load https://xxxxxx.jsreportonline.net/api/report. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://sample.local:8090' is therefore not allowed access. The response had HTTP status code 500.
For your information sample.local:8090 is the url of the web application running locally on my pc in a xampp environment.
Please help me understand where I'm going wrong!!
-
This is some kind of jquery weird implementation of CORS, because the native xmlhttprequest works find for me in this scenario.
You have these options:
- Google out the jquery CORS errors
- Use native xmlhttprequest to do the request, it is just like 10 lines of code
- Use our jsreport official client for browser - https://jsreport.net/learn/browser-client
- Proxy requests to jsreportonline through your server