//Create an Angular Module. var newsModule = angular.module('NewsModule', []); //Create an Angular Controller. newsModule.controller('newsCtrl', ['$scope', '$http', function ($scope, $http) { //function retrives POST,UPDATE,DELETE,GET data $http.defaults.headers.put = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With' }; $http.defaults.useXDomain = true; $scope.throughdata = function (){ delete $http.defaults.headers.common['X-Requested-With']; $http.get('http://www.google.com').then(function(data,error){ alert(data); alert(error); $scope.days=data.data; }); } } ]);
But I have getting following errors
XMLHttpRequest cannot load http://www.google.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
In that case you can change the security policy in your Google Chrome browser to allow Access-Control-Allow-Origin. This is very simple: Create a Chrome browser shortcut. Right click short cut icon -> Properties -> Shortcut -> Target.
Access-Control-Allow-Origin
is set on the response from server, not on client request to allow clients from different origins to have access to the response.
In your case, http://www.google.com/ does not allow your origin to have access to the response. Therefore you cannot read it.
For more information about CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With