<a href="www.myfile.json" download>download file</a>
"www.myfile.json" is a link to a json file. My goal is when user clicks "download file", the json file is downloaded automatically. However, with above code, when I click "download file", it opens the json file in browswer for me. I would like to know what I am doing wrong here.
I have tried the solution in this link(Chrome 65 blocks cross-origin <a download>. Client-side workaround to force download?), but I got Access to fetch at 'XXXXX' from origin 'XXXX' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. However, I do set 'Access-Control-Allow-Origin':'*' in my request header. I am not able to modify anything on server side. What should be the right way to do for me?
My header looks like below:
headers: new Headers({
'Origin': location.origin,
'Access-Control-Allow-Origin': '*',
}),
mode: 'cors'
})
Besides, I also tried set mode: 'no-cors', but it does not work.