I am using AngularJS to make calls to a remote unit that supports JSON API. The call is proceeded as this:
'use strict';
var app=angular.module('app', [])
app.controller('Login', function ($scope, $http) {
$scope.login = function () {
$scope.user;
$scope.passwd = "";
$scope.message = "";
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
$http.post('http://192.168.30.1/jsonrpc',
{
"params": [{
"url": "sys/login/user",
"data": [{
"passwd": $scope.passwd,
"user": $scope.user,
}]
}],
"session": 1,
"id": 1,
"method": "exec"
}).then(function (response) {
if (response.result.status.code == 0) {
$scope.message = 'Bienvenue'
}
else {
$scope.message = 'Non authetifie'
}
}, function () {
$scope.message = 'erreur'
})
}
} );
As shown in the code above, The second argument in $http.post
is some JSON data which will be sent to the remote unit and the response is also JSON.
When I send a request I can see the JSON response with fiddler but in the $scope.message I get erreur
since for the javascript no response was received.
Since I am falling in the CORS problem, I want to know can I send this same data as JSONP using $http.jsonp
?
The reason for my question is that $http.jsonp
only takes the url
and [config]
as parameters unlike $http.post
so I can't send my JSON data with it.