Hey getting error mentioned above. It is running fine on mobile but not on browser.preflight has invalid HTTP status code 403. Backend developer says he has coded everything perfectly at the backend. So in case if something is possible at the frontend let me know please. I have downloaded "CORS" extension in chrome.
Controller.js
.controller('LoginCtrl', function($scope, $http,$rootScope,$window,$location,$state) {
$scope.formData = {};
$scope.processForm = function() {
$http({
method : 'POST',
url : 'http://abc/login',
data : $.param($scope.formData),
headers : { 'Content-Type': 'application/x-www-form-urlencoded', 'X-API-KEY': 'abcfjo-jrabc-ltjerabcabcabc' }
})
.success(function (data, status, headers, config) {
$scope.foo = data;
$state.go('tab.dash');
// $location.path('#/tab/new-order');
})
.error(function (data, status, header, config) {
$window.alert("username or password incorrect");
});
};
})
html
<form action="" class="ki-login-form" method="post" accept-charset="utf-8" >
<div class="form-group username">
<input type="text" class="form-control" name="username" ng-model="formData.username" value="" id="identity" placeholder="Your Name">
</div>
<div class="form-group pin">
<input type="text" class="form-control" name="password" ng-model="formData.password" value="" id="identity" placeholder="Your Pin">
</div>
<a type="submit" class="btns" ng-click="processForm(formData.username,formData.username)">Login</a>
</form>
app.js
angular.module('starter', ['ionic','starter.controllers', 'starter.services', 'ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider,$httpProvider) {
$stateProvider
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'templates/tabs.html'
})
Error XMLHttpRequest cannot load http://abc/login. Response for preflight has invalid HTTP status code 403