In the case of the new company project I’m working on, to access the company’s interface to retrieve data, you just create a new file called index.html locally. That’s not enough. When you retrieve data using Ajax, you get an error
XMLHttpRequest cannot load URL No ‘access-Control-allow-origin’ header is present on the requested resource. Origin ‘null’ is therefore not allowed access.
So, you need http-Sever
npm install http-server -g
And then in your project directory
http-server
Open the
localhost:8080
See if it’s the project you’re in
Next you can point 127.0.0.1 to a URL, and when you run the program, you can enter your URL and run it. So how do you point 127.0.0.1 to the URL you want?
In finder – “Go to folder -” type /private/etc, press Enter, find the hosts file, copy it to your desktop, and make changes.
127.0.0.1 localhost 255.255.255.255 Broadcasthost ::1 localhost 127.0.0.1 IP address that you want to enterCopy the code
After the changes are made, copy the files back (there is no permission to make changes directly in the hosts file, so copy the files out and back).
Baidu.com :8080 = baidu.com:8080 = baidu.com:8080