angularjs - Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at ..... -


when using $http.get have problem: cross-origin request blocked: same origin policy disallows reading remote resource @ ..... can fixed moving resource same domain or enabling cors

$http.get('...').success(function(data){         console.log(status);     }).error(function(data){         //console.log(data)     }); app.config(['$httpprovider', function($httpprovider) {         $httpprovider.defaults.usexdomain = true;         delete $httpprovider.defaults.headers.common['x-requested-with'];     } 

cross-origin requests requests made 1 domain different 1 (in client side). default prohibited in web security reasons. so, if have webpage in http://www.yours.com making ajax request http://www.other.com/get/resource, ajax request rejected. issue can resolved in 3 ways :

  • fetch api (/get/resource) in http://www.yours.com request not cors request anymore.
  • transform architecture of application, request http://www.yours.com made in backend (aka not in form of ajax) , passed on webpage.
  • enable server in http://www.other.com allow cors requests http://www.yours.com. can done adding header origin: http://www.yours.com in responses of server. thus, requires have access second server's configuration.

additional resources cors :

  1. html5 turorial
  2. w3 specification

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -