php


No 'Access-Control-Allow-Origin' error with PHP Nginx


I'm using laravel for my backend and trying to send request with jQuery to Instagram api but I'm getting this error while response is OK in Chrome browser inspector
test?code=a3679b3…:1 XMLHttpRequest cannot load https://api.instagram.com/oauth/access_token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com' is therefore not allowed access.
and this is my code to send request
$.ajax({
method: 'POST',
url: 'https://api.instagram.com/oauth/access_token',
data: {
client_id: "client_id",
client_secret: "client_secret",
grant_type: "authorization_code",
redirect_uri: "example.com",
code: "{{$code}}"
}
});
I've tried to add Access-Control-Allow-Origin in my Nginx default.conf file but that not solved my problem. How can I fix it?
This error messages is because of CORS. In your browser, your AJAX request should be on the same origin. So if you are using example.com, Chrome will only support AJAX requests to example.com. Except, if an other domain (like api.instagram.com) has an Acces-Control-Allow-Origin header. You can read more about this here:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
You could try to acess Instagram from your backend. This way your AJAX request is going to your backend on the same origin, and your backend can easily access Instagram's API.
Also you can try dataType: "jsonp", in this answer you can find out more:
instagram jquery ajax type="GET, can't get around CORS

Related Links

Throw an error when PHP session is not writable?
Creating a new folder in another folder using PHP with name from input
Regex/preg_match - get text between string and email address
htaccess pretty urls redirects the wrong way
How to secure requests or/and responds from server
PUT action type is incorrect in CakePHP 3
live chart for heartbeats
Laravel get top 5 id's with most records
Laravel 4.2 Not Returning View::make
Trying to Get Property of non-object in PHP JSON
Pass constructor arguments to inherited child class
Prevent Replacing session in CodeIgniter
Paypal: How to display payer's email on the thank you page?
Trying to recieve object in route - Laravel
Paramaters to anonymous functions in php
How to encrypte and decrypte laravel 5.4.6 class object

Categories

HOME
libgdx
opencart
gaming
cucumber
clearcase
writefile
plpgsql
google-webmaster-tools
visualforce
ipv6
kurento
elastic-load-balancer
lc3
lapack
locationmanager
alljoyn
graphdb
game-maker
bootstrap-switch
mailgun
bnf
tomcat8
cocos2d-android
office-ui-fabric
raml
error-logging
hdl
connection-refused
sipp
background-color
xdebug
running-object-table
tilemill
delayed-job
series
lxml
cordys-opentext
reset
ejml
google-prediction
beeline
amazon-elastic-beanstalk
winston
sigsegv
patternlab.io
dymola
ogg
haraka
cefpython
clp
svnserve
gnucash
okta-api
trust
wikimedia-commons
grinder
helm
python-cffi
in-app-billing
arbre
cfwheels
supercomputers
uitest
gflags
fiware-bosun
uno
ildasm
visual-studio-6
loginview
webmethod
full-text-indexing
hyperloglog
zend-search-lucene
cpu-time
ctp
frontbase
rautomation
django-facebook
dynamic-rdlc-generation
delphi-xe4
html-frames
tfs-sdk
struts2-json-plugin
platform-independent
firebird1.5
prototypal-inheritance
kolite
n-queens
differentiation
radscheduler
kernel32
aggregator
resharper-5.0
twitter-feed
server-load
service-factory

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile