Access to XMLHttpRequest at 'https://dailymed.nlm.nih.gov/dailymed/services/v2/drugnames.json?drug_name=as' from origin 'https://test.local' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Asked
Active
Viewed 371 times
-2
-
Does this answer your question? [How to allow Cross domain request in apache2](https://stackoverflow.com/questions/29150384/how-to-allow-cross-domain-request-in-apache2) – nopassport1 Jan 20 '20 at 16:19
-
1@nopassport1 - Only useful, of course, if the OP is part of the team running `dailymed.nlm.nih.gov`... :-) – T.J. Crowder Jan 20 '20 at 16:21
-
3There are hundreds of questions about CORS and the SOP on Stack Overflow that already have answers. How, **specifically**, is your question different from (say) [this one](https://stackoverflow.com/questions/37527962/add-cors-header-to-an-http-request-using-ajax)? – T.J. Crowder Jan 20 '20 at 16:22
-
1You will not be able to do that from JavaScript because that website does not allow CORS. You can get around this if you use a back-end like PHP or ASP.NET then use an HTTP web request from there and parse it. – Jesse Jan 20 '20 at 16:22
1 Answers
2
You can try to use fetch
with proxy to make a request:
var proxy_url = 'https://cors-anywhere.herokuapp.com/';
var main_url = 'https://dailymed.nlm.nih.gov/dailymed/services/v2/drugnames.json?drug_name=as';
fetch(proxy_url + main_url)
.then(response => response.json())
.then(data => console.log(data));

Tân
- 1
- 15
- 56
- 102