Can use axios to get external data?

got network error always. anyone can help? thanks!

Could you link to an example notebook that illustrates the issue?

As I understand it, thereā€™s less of a reason to use Axios now that the Fetch standard is supported by modern browsers. Perhaps you are running into CORS issues? Have you read the introduction to data notebook?

1 Like

I need data from remote js file, like this ā€œhttp://lol.qq.com/biz/hero/champion.jsā€, I want to load it directly instead of saving it to local. Sorry, I am a new developer, maybe there is better way to implement.

Sounds like you need a CORS proxy. You canā€™t fetch directly from an HTTP site (HTTPS is required) and the server must have CORS enabled. You can try the demo instance of CORS-Anywhere to start.

For what itā€™s worth, I tried to use a few different CORS proxies to load your data, but without success:

I couldnā€™t get CORS-anywhere to work at all. The other two proxies send the JS file with the wrong MIME Content-type: cors.io sends it as text/html and codetabs sends it as text/plain.

This might be a bit confusing at first because the file isnā€™t data - itā€™s JavaScript code. So solving CORS, using axios, and other steps arenā€™t directionally right. You can, however, achieve what you want to do:

require("https://lol.qq.com/biz/hero/champion.js").catch(() => window.LOLherojs)

This uses require(), our method for including code, but since champion.js doesnā€™t implement UMD or any sort of ā€˜module definitionā€™ standard and instead just leaves a variable behind, we catch that variable (what I call the ā€˜global leaks patternā€™ in the module debugger).

(The other minor quirk is that I changed the URL from http:// to https://. qq.com supports both, but http:// wonā€™t work with Observable or any SSL website).

3 Likes

Thanks for your time!

Thanks!

It works!!! Really appreciate!