No 'Access-Control-Allow-Origin' header is present (CROS) - javascript

From html page using javascript ajax call am trying to call Login_check api (REST webservice) but am getting error as below.
XMLHttpRequest cannot load
http://184.30.53.119:8080/Automation_test1/TRTS/login/Login_Check. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

JavaScript has a same-origin policy. Which means it cannot request pages on other domains. You have a couple of options to do this, use JSONP or have a php script that you call to query the api.
More information: Working With and Around the Same-Origin Policy

Related

CORS error while loading files from the same domain

I'm working on website http://www.fsvelicka.cz. I need to load a content of an HTML file to an element. I have an element and I'm loading the content with $('.about-us-first-col').load("about_us/desc/" + lang + "/first_col.html"); The problem is I'm getting an error:
Access to XMLHttpRequest at 'https://www.fsvelicka.cz/first_col' (redirected from 'http://www.fsvelicka.cz/first_col.html') from origin 'http://www.fsvelicka.cz' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
The element is inside index.html file and the file I want to load is located in about_us/desc/cz/. I don't understand why I'm getting this error while the file is in the same domain.
CORS cares about the origin of which the domain is only one part.
To be on the same origin each of:
The scheme
The full hostname
The port number
… must match.
Your URLs have different schemes. One is https, the other is http. They are not the same origin.
Generally speaking, you want to be using HTTPS wherever possible. Redirect all requests from your plain HTTP service to HTTPS. That way the HTML page will be served over HTTPS and the origins will match.

How To Fix " No 'Access-Control-Allow-Origin' header is present on the requested resource."

I am trying to get data from another server using YouTube Video playback link but I am getting this error:
Failed to load
https://r12---sn-aigllnd7.googlevideo.com/videoplayback?requiressl=yes&clen=2193105&signature=109DA57913EC4535C3AC8FB84356B9ABCD11D6C4.A8547FC1740F9913D3FEB1335605AF3477F2BA88&ipbits=0&mime=video%2Fmp4&initcwndbps=2508750&itag=18&ratebypass=yes&expire=1509471177&sparams=clen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&key=yt6&beids=%5B9466593%5D&gir=yes&id=o-AK9XTzJjMCSwyCVnb7md1uikHohpJqRX-MzC6VOT3BNa&mn=sn-aigllnd7&mm=31&pl=48&dur=28.560&lmt=1500337266737259&ip=2a02%3A4780%3Abad%3A16%3Afced%3A1ff%3Afe16%3A333&ms=au&ei=aV_4WabyCcTckAOJ_IHoBQ&mt=1509449472&mv=m&source=youtube:
Redirect from 'https://r12---sn-aigllnd7.googlevideo.com/videoplayback?requiressl=yes&clen=2193105&signature=109DA57913EC4535C3AC8FB84356B9ABCD11D6C4.A8547FC1740F9913D3FEB1335605AF3477F2BA88&ipbits=0&mime=video%2Fmp4&initcwndbps=2508750&itag=18&ratebypass=yes&expire=1509471177&sparams=clen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&key=yt6&beids=%5B9466593%5D&gir=yes&id=o-AK9XTzJjMCSwyCVnb7md1uikHohpJqRX-MzC6VOT3BNa&mn=sn-aigllnd7&mm=31&pl=48&dur=28.560&lmt=1500337266737259&ip=2a02%3A4780%3Abad%3A16%3Afced%3A1ff%3Afe16%3A333&ms=au&ei=aV_4WabyCcTckAOJ_IHoBQ&mt=1509449472&mv=m&source=youtube' to 'https://r2---sn-ug5onfvgaq-aixl.googlevideo.com/videoplayback?requiressl=yes&clen=2193105&signature=2E5AA33529609CA727EB8BE12AA33FBDAAFA116F.02E023B012CCA899379E83DAC38CF55D9072907D&ipbits=0&mime=video%2Fmp4&itag=18&ratebypass=yes&expire=1509471177&sparams=clen,dur,ei,expire,gir,id,initcwndbps,ip,ipbits,ipbypass,itag,lmt,mime,mip,mm,mn,ms,mv,pl,ratebypass,requiressl,source&key=cms1&beids=%5B9466593%5D&gir=yes&id=o-AK9XTzJjMCSwyCVnb7md1uikHohpJqRX-MzC6VOT3BNa&pl=24&dur=28.560&lmt=1500337266737259&ip=2a02%3A4780%3Abad%3A16%3Afced%3A1ff%3Afe16%3A333&ei=aV_4WabyCcTckAOJ_IHoBQ&source=youtube&redirect_counter=1&rm=sn-aigeez7s&fexp=9466587&req_id=7a988fa941a7a3ee&cms_redirect=yes&ipbypass=yes&mip=210.56.10.190&mm=31&mn=sn-ug5onfvgaq-aixl&ms=au&mt=1509449472&mv=m'
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
Can You Please tell me how i can fix this error.
Thanks for your precious time.
CORS enabled on the server side, so you can't fix this on your code. In some cases, you can try to use a request type of JSONP but not in this case.

Is there any way to call instagram api without access token

I am trying to call https://www.instagram.com/"+username+"/?__a=1 but getting below error.
'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.
But the URL is working on browser
?__a=1 method does not support JSONP, so you cannot make the API call client side, you can make http get request on server side.

Ajax call to API not working

I am trying to retrieve data from an API using Jquery's ajax(), but it doesn't work with this implemenation:
$.ajax('http://api.forismatic.com/api/1.0/?method=getQuote&format=json').done(function(data) {
alert(1);
alert(JSON.stringify(data));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
After running the code the alert function doesn't work, so I concluded that the success callback function isn't working, but I have no idea why.
After inspecting the server response headers, there is no Access-Control-Allow-Origin, this means that the server doesn't allow cross-origin access. Since you make a cross-origin HTTP request, your request will be rejected by the browser following the Same-origin policy:
The same-origin policy restricts how a document or script loaded from
one origin can interact with a resource from another origin. It is a
critical security mechanism for isolating potentially malicious
documents.
Look at your console you will see the following error (Chrome):
XMLHttpRequest cannot load
http://api.forismatic.com/api/1.0/?method=getQuote&format=json. No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://s.codepen.io' is therefore not allowed
access.
For more details please refer to: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

Parse JSON to HTML with jquery

I need to parse this JSON link
http ://www.mse.mk/FreeMseFeeds/service/FreeMSEFeeds.svc/ticker/JSON/9538ac69-2c99-45ba-bbd4-90931ca0cc7d
to be same like on this page:
http ://www.mse.mk/en/
image:
http: //tinypic.com/r/1zlyhwo/8
I've tried like this:
$.getJSON("http://www.mse.mk/FreeMseFeeds/service/FreeMSEFeeds.svc/ticker/JSON/9538ac69-2c99-45ba-bbd4-90931ca0cc7d",function(data){
alert(data[0].name);
});
I got this error:
XMLHttpRequest cannot load
http:// www.mse.mk/FreeMseFeeds/service/FreeMSEFeeds.svc/ticker/JSON/9538ac69-2c99-45ba-bbd4-90931ca0cc7d.
No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http: //kristijanz.com' is therefore not allowed
access.
Any help ?
Looks like a CORS issue - your application calling www.mse.mk/FreeMseFeeds/service/FreeMSEFeeds.svc/ticker/JSON/9538ac69-2c99-45ba-bbd4-90931ca0cc7d is not running in the same domain.
If you control the service, you can implement CORS to allow other domain origins.
If you do not, you cannot call this service from your domain.
CORS - https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

Categories