angularjs - Angular js : Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource -



angularjs - Angular js : Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource -

i getting error when trying post info using $http.post() in angular js.

cross-origin request blocked: same origin policy disallows reading remote resource @ {{post url}}. can fixed moving resource same domain or enabling cors.

this code :

var ionicappcontrollers = angular.module('ionicappcontrollers', []); ionicappcontrollers.config(function($httpprovider) { //enable cross domain calls $httpprovider.defaults.usexdomain = true; //remove header containing xmlhttprequest used identify ajax phone call //that prevent cors working delete $httpprovider.defaults.headers.common['x-requested-with']; }); ionicappcontrollers.controller('createitemctrl', ['$scope', '$http', function($scope, $http) { $scope.parts = []; $scope.add = function() { $scope.parts.push({ id: '', code: '', description: '' }); }; $scope.submititemform = function(isvalid) { if (isvalid) { $scope.postdata = {}; $scope.postdata.item = $scope.item; $scope.postdata.description = $scope.description; (var in $scope.parts) { (var j in $scope.parts[i]) { if (j == '$$hashkey') { delete($scope.parts[i][j]); //console.log(j); } } } $scope.postdata.parts = $scope.parts; console.log($scope.postdata); $http({ method: 'post', url: 'url', data: $scope.postdata, // pass in info strings headers: {'content-type': 'application/json'} }).success(function(data) { if (data.success) { alert('sucess'); } else { alert('fail'); } }); } }; $scope.add(); }]);

this has nil angular . server application should enable or allow request generated angular application hosted or running on machine . if running app in localhost. utilize cors extension chrome. if other server . lets www.example.com .

the server code must changed nil on front end end perspective .

please refer link. http://enable-cors.org/server.html

angularjs angularjs-directive angularjs-scope cors

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -