+ 3

How can i resolve the error no access control allow orgin header is present on requested source

So I am making a Ajax call using jQuery load and I get the above error https://code.sololearn.com/WH5kPnwyIiGW/?ref=app

17th Jun 2020, 12:05 PM
Abhay
Abhay - avatar
11 Answers
+ 1
By installing cors library from npm. I think. https://youtu.be/dXjKh66BR2U
17th Jun 2020, 12:09 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
+ 3
🇮🇳Omkar🕉 thank you very much ,I just jumped to code you provided and didn't understand how would it helped with my code and I didn't noticed that dl
17th Jun 2020, 4:00 PM
Abhay
Abhay - avatar
+ 2
🇮🇳Vivek🇮🇳 ty but I replaced link in your code with mine and still getting same error ,also I know nothing about how would i use cors library with jQuery
17th Jun 2020, 12:37 PM
Abhay
Abhay - avatar
+ 2
Abhay , Use this link instead https://dl.dropbox.com/s/0rvmkr4tjsx4wkw/myfile.txt?raw=1 You need to replace www by dl and use query string ?raw=1 at end. https://code.sololearn.com/WV796n6dPtJe/?ref=app
17th Jun 2020, 12:42 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 2
ODLNT thank you very much ,all day i was searching about cors and read that requested source should have access control policy origin set to * for other domain ,and didn't came across any solution ,and its really shocking to me how www replaced with dl and adding?raw=1 works fine,guess I need to learn about the link themselves !
17th Jun 2020, 3:59 PM
Abhay
Abhay - avatar
17th Jun 2020, 12:23 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
+ 1
🇮🇳Omkar🕉 That's a different thing I can upload the text from file using iframe tag ,I am talking about Ajax call here ,which returns the error I said ,I searched about it and didn't found any solution at all ,since CORS prevent access of data from other domain ,I can't access it ,but I want to know how can I solve it
17th Jun 2020, 12:53 PM
Abhay
Abhay - avatar
+ 1
Abhay you have not any access to that website you are trying to post something. Jsonplaceholder is a service for all. Anyone can access that website. Example - > if you have a website. Then you will put authentication or not for website . Or you will allow everyone to still your user data. Cors simply means you are not authorized or authentic person to post, get, update or create data
17th Jun 2020, 2:04 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
+ 1
Yes I read about that Vivek ,so how can i get data from my text file ?where should I upload it which allows me to get data
17th Jun 2020, 2:53 PM
Abhay
Abhay - avatar
0
Why you want to upload your file? If you want to upload your text file to your cloud service provider. Same problem will be there. Ask your cloud service provider to give access to their api. Other wise there will be know way to get data from cloud. If you want to get data from a text file which is in your local machine you can get data from that file with any ajax call. There will not be cors.
17th Jun 2020, 3:16 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar