I don't sure if it's related to ionic or the fact that it runs currently on localhost, but request returns with Request Method: OPTIONS, 400 instead of POST and returns 400.
what can be the problem?
this is the API I use: https://languagetool.org/http-api/swagger-ui/#!/default/post_check
and this is my code :
factory.checkText = function(text) {
var language = "en-US";
var reqUrl = "https://languagetool.org/api/v2/check";
var data = {
language: language,
text: text,
enabledOnly: false
};
var deferred = $q.defer();
var request = {
method: 'POST',
url: reqUrl,
dataType: "json",
contentType: "application/json; charset=utf-8",
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache',
'X-Requested-With': 'XMLHttpRequest',
'Access-Control-Allow-Origin': '*'
},
data: JSON.stringify(data),
};
$http(request).success(function(data) {
deferred.resolve(data);
}).error(function(error) {
deferred.reject(error);
});
return deferred.promise;
}
If I use
params: data
instead of
data: JSON.stringify(data)
, I still get OPTION but with 200. but error event is fired, so I can't read the response.