The code you have written is correct, there are a few reasons why it gets that error:
CORS - if you're trying to fetch a resource from a different origin, the server must allow your origin to access it. If it doesn't, the browser will block the request.
Network Issues
Incorrect URL
If you can share the specific site you are trying to retrieve, I may be able to look at it and provide more targeted advice.