Today, I developing a web app using to AngularJs and REST API. The REST APIs are hosted on some different servers. When I calling to this REST APIs that time I facing this issues[ CORS ( Cross Origin Request Sharing )] and solved this issue now using the below stuff. In the below example we set the $httpProvider.defaults.useXDomain = true ; that means the AJAX request send with X-Requested-With and Removing the necessary header, so the server is not rejecting the all incoming request . In AngularJs version > 1.2, No need to any other extra work. Simply you add stuff in the app config file. The code sample as given below. var app = angular.module( 'corsApp' , []); app.config([ '$httpProvider' , function ($httpProvider) { $httpProvider.defaults.useXDomain = true ; delete $httpProvider.defaults.headers.common[ 'X-Requested-With' ]; ...
Angular, React, JavaScript, Java, PHP, SQL, C#, Vue, NodeJs, TypeScript and Interview Questions Answers