My Sever side is php/mysql.
I am making Ajax call in webservice of another domain(Which have access control enabled for *)
var postUrl = "http://logical-brains.com/elance_clone/test_login.php";
var postData = {username : "tanmoy" , password : "123456"};
I tried by Simple jQuery :
$.ajax({
type: "POST",
url: postUrl,
data: postData,
dataType: "json",
crossDomain: true,
success: function(data){ console.log(JSON.stringify(data)); }
});
It worked fine and I got Status Code:200 OK with expected result.
BUT When I am trying by AngularJs , getting below Error :
XMLHttpRequest cannot load http://logical-brains.com/elance_clone/test_login.php. Request header field Content-Type is not allowed by Access-Control-Allow-Headers.
AngularJs Code :
var myApp = angular.module('myApp', []);
myApp.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
}]);
myApp.controller('MainCtrl', function($scope, $http) {
var postUrl = "http://logical-brains.com/elance_clone/test_login.php";
var postData = {username : "tanmoy" , password : "123456"};
$http({
url: postUrl,
method: "POST",
data: postData,
crossDomain: true
})
.then(function(result) {
console.log("Success", result);
$scope.someVal = JSON.stringify(result);
},
function(response) { // optional
console.log("error "+response);
}
); }; });