Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
109
rated 0 times [  111] [ 2]  / answers: 1 / hits: 38243  / 8 Years ago, wed, september 7, 2016, 12:00:00

I'm having an issue with PDF.js and CORS configuration.



From domain A I'm loading PDF.js into an iframe with a file as parameter (full path to the server, which will return a pdf document). PDF.js will create a request to the server at domain B with origin: domain A. The server at domain B returns the pdf document with header Access-Control-Allow-Origin: domain A, so far so good.



In my network tab I see the request to the server, which is returning a 200 status OK, but PDF.js is throwing an error Unexpected server response (0) while retrieving PDF <url>.



The question is, what's going on here, CORS seems to be ok, but I can't really get any more info from PDF.js what the real reason is the PDF is failing to load. Is there anyone who encountered the same?


More From » pdf

 Answers
6

Finally found the problem. My server was not passing the Access-Control-Allow-Credentials: true header to the response, which was needed (xhr request was sent with xhr.withCredential).



CORS is now working properly.



Found the solution at: https://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/


[#60784] Monday, September 5, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ibrahimgilbertoz

Total Points: 420
Total Questions: 112
Total Answers: 92

Location: Bonaire
Member since Sat, May 1, 2021
3 Years ago
;